Jump to content
 
  • 0
Orunmila

PIC32 Linker scripts in MPLAB-X

Question

I am trying to use a linker script with MPLAB-X for my PIC32 project but for some reason the script is not being passed to the linker at all. I expected that all I had to do was add the .ld file to my project, typically by placing it in the "Linker Files" virtual folder in MPLAB-X in my project. I did this and the linker script is being ignored by the linker.

This is one of those $100 questions (if you know the story of the mechanic asking $100 for knowing where to hit ...).

So my question is how do I get MPLAB-X to use my linker script which I have added to the PIC32 project?

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Use a less buggy version of MPLAB-X? Hard to choose, I know.

I pulled up my old project in MPLAB-X 2.35 and it's pulling my .ld file from MPLAB's Linker Files folder.

Share this post


Link to post
Share on other sites
  • 0

Ok great news I figured out what was going wrong!

I was working with an old project file. The project was not using a linker script before.

It turns out that MPLAB is doing all kinds of strange things in the background to figure out that it has to treat files in the Logical Folder called by "name=LinkerScript" and "displayname=Linker Files" as linker scripts instead of C files, and once it has gotten itself confused about this there is no going back without recreating the entire project file. Now since ours contained hundreds of source files we tried to avoid this but alas, turns out there is not really another way :(

There is an example here https://www.microchip.com/forums/m651658.aspx on how to add the item back in. This seems to only work if you add it in AND rename the item BEFORE opening the project in MPLAB-X, if you open the project first you will be out of luck.

For now you will have to do a lot of trial and error, or just re-create the project if you need to add a linker script, and even then good luck, the IDE can muck it up quite easily!

I think I see a blog post coming on how to get a linker script into your MPLAB-X project. It seems to be harder than it should be!

Edit: I have written up my experience in a blog entry here:

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 


  • Popular Contributors

  • Similar Content

    • By Orunmila
      I have a MPLAB-X project which uses a loadable (it is combining my program with a bootloader which is in another project). 
      I need to compile this project from the command line for CI automation. For the entire build process every command executed is nicely printed in the build window, but for the loadable it claims to be using Hexmate, but the command line to execute it is not shown at all.
      Can anyone help me with the syntax using Hexmate to get the same behavior as adding the Loadable from MPLAB-X?
    • By Orunmila
      I am trying to pass an include file name on the command line to XC32 to select the file to include in the code. Don't ask why, this is not my code, I am just trying to compile it with this compiler without modifying the code ...
      I am passing 
      -DCONFIG_FILE=\"demo_config.h\" but the compiler does not seem to like this, error message is 
       error: #include expects "FILENAME" or <FILENAME> Anyone know how to bend XC32 to my will here to do this correctly?
       
      EDIT: I have confirmed that this works fine on vanilla GCC. On MCHP XC32 I can do this and then it compiles fine
      #undef CONFIG_FILE #define CONFIG_FILE "demo_config.h" #include CONFIG_FILE It seems like when I pass in the filename via the command line something weird and unexpected is happening ...
      I used a trick to print the value and the filename is ending up in the code correctly it seems ...
      #define XSTR(x) STR(x) #define STR(x) #x #pragma message "The include is " XSTR(CONFIG_FILE) #ifdef CONFIG_FILE     #include CONFIG_FILE #endif This will produce:
      #pragma message: The include is "demo_config.h" error: #include expects "FILENAME" or <FILENAME>  
    • By dvvrao
      Does the simulator for PIC32MX470F512L support UART with DMA operation? 
      I wrote a program that transmits a character using UART with DMA, but does not work. 
      I used Dynamic USART driver with Buffer Que Data Transfer model using DMA.
      PFA the package file of the project.
      Please let me know if there is any thing wrong with the code or harmony configuration.
      usart_loopback.zip
    • By Orunmila
      I just downloaded XC32 V2.15, I was using V2.10 before. I find that some of my projects no longer compile. On my first check I noticed that the problems seem to occur when inline functions are used and the same header where the inline implementation is done is included in more than one compilation unit?
      Has any of you seen similar issues?
      I will investigate further and post here if I arrive at an answer.
       
      UPDATE: Ok, I managed to make a small test project to replicate the problem. I am attaching it here. 
      TestInlineXC32_2.15.zip
       
      Next I am going to test this on some other compilers to see what the deal is. I have confirmed that with that project when you switch it to V2.10 or older it all compiles just fine, but if you use V2.15 it failes to link with the following error:
      "/Applications/microchip/xc32/v2.15/bin/xc32-gcc"   -mprocessor=32MZ2048EFM100  -o dist/default/production/TestInlineXC32_2.15.X.production.elf build/default/production/main.o build/default/production/otherFile.o          -DXPRJ_default=default  -legacy-libc    -Wl,--defsym=__MPLAB_BUILD=1,--no-code-in-dinit,--no-dinit-in-serial-mem,-Map="dist/default/production/TestInlineXC32_2.15.X.production.map",--memorysummary,dist/default/production/memoryfile.xml
      nbproject/Makefile-default.mk:151: recipe for target 'dist/default/production/TestInlineXC32_2.15.X.production.hex' failed
      make[2]: Leaving directory '/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X'
      nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
      make[1]: Leaving directory '/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X'
      nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
      build/default/production/otherFile.o: In function `myInlineFunction':
      /Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X/inlinedheader.h:6: multiple definition of `myInlineFunction'
      build/default/production/main.o:/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X/inlinedheader.h:6: first defined here
      /Applications/microchip/xc32/v2.15/bin/bin/gcc/pic32mx/4.8.3/../../../../bin/pic32m-ld: Link terminated due to previous error(s).
      collect2: error: ld returned 255 exit status
      make[2]: *** [dist/default/production/TestInlineXC32_2.15.X.production.hex] Error 255
      make[1]: *** [.build-conf] Error 2
      make: *** [.build-impl] Error 2
      BUILD FAILED (exit value 2, total time: 680ms)
       
       
       
×
×
  • Create New...