cannot link to static library

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

cannot link to static library

Jump to solution
1,882 Views
mike1974
Contributor III

I have created a library in one project, but I can't seem to link to it in another project which uses it.

 

I have done:

 

Properties --> C/C++ Build --> Settings --> Tool Settings --> Libraries -->

 

  1) added name of library in the -I field, without .a extension or "lib" prefix

  2) added libraries physical location in the -L field.

 

I am still getting "undefined reference" to functions which I have double checked are in fact in the library.

 

Am I missing a something?

 

--Mike

Labels (1)
0 Kudos
1 Solution
1,325 Views
mike1974
Contributor III

Hmm I just noticed I'm using "ObjectList" ( a text file) as the input of .o files to use.  I did this to get around the Windows command line limit (8192 chars).  I just saw this morning on mcuoneclipse.com that there is a fix for that.  I wonder if this could be causing it?

View solution in original post

0 Kudos
8 Replies
1,325 Views
mike1974
Contributor III

I should add, that I'm compiling C++ code, and the library is all C code.  So perhaps that's the issue?

0 Kudos
1,325 Views
BlackNight
NXP Employee
NXP Employee

Hi Michael,

are you using properly

extern "C"

for everything you interface from C++ to C?

Erich

0 Kudos
1,325 Views
mike1974
Contributor III

Hi Erich,

Yes, the library I'm building is a GUI from Segger, it should build fine with a C++ application.  Each .h file in the GUI has:

#if defined(__cplusplus)

extern "C" {     /* Make sure we have C-declarations in C++ programs */

#endif

Furthermore, I was already building the entire GUI as part of my C++ application.  It compiled and linked fine, but it was too many files, so I decided to make the GUI a library and link to it.

0 Kudos
1,325 Views
BlackNight
NXP Employee
NXP Employee

If you run the 'nm' utility (Defining Variables at Absolute Addresses with gcc | MCU on Eclipse), do you see the proper symbols?

Erich

0 Kudos
1,325 Views
mike1974
Contributor III

Erich, I downloaded the new make (and rm and echo) as instructed here:

Solving the 8192 Character Command Line Limit on Windows | MCU on Eclipse

Now, I can link.  However, the linker complains that the library I'm using does not have VFP (vector floating point) register arguments, but that my application does.  Apparently this prevents me from linking. 

So, do you know where the setting is that allows me change my library to use VFP arguments as well?

1,325 Views
mike1974
Contributor III

Found the setting, it's

Properties --> C/C++ Build --> Settings --> Target Processor --> Float ABI.  

I set it to "FP instructions (hard)" on both my project and the library, I can now link successfully.  Life is good... for now :--)

1,325 Views
mike1974
Contributor III

Hi Erich, here is the complete linker command line, as well as the output.  I clipped the output a bit, because it was very long, but it just repeats over and over "undefined reference"...

'Invoking: Cross ARM C++ Linker'

arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections  -g3 -T "C:/M2/Project_Settings/Linker_Files/ProcessorExpert.ld" -Xlinker --gc-sections -L"C:/M2/Project_Settings/Linker_Files" -L"C:\kds_workspace\Segger-GUI\Debug" -Wl,-Map,"M2.map" -nanolibc -o "M2.elf" @ObjectList

./Sources/Application/Menu/Screen_Callbacks.o:(.data._ZL7_apFont+0x0): undefined reference to `GUI_Font16B_1'

./Sources/Application/Menu/Screen_Callbacks.o:(.data._ZL7_apFont+0x4): undefined reference to `GUI_Font20B_1'

./Sources/Application/Menu/Screen_Callbacks.o:(.data._ZL7_apFont+0x8): undefined reference to `GUI_Font8x16x2x2'

./Sources/Application/Menu/Screen_Callbacks.o:(.data._ZL7_apFont+0xc): undefined reference to `GUI_Font8x10_ASCII'

./Sources/Application/Menu/Screen_Callbacks.o:(.data._ZL7_apFont+0x10): undefined reference to `GUI_FontD24x32'

./Sources/Application/Menu/Screen_Callbacks.o:(.data._ZL7_apFont+0x14): undefined reference to `GUI_Font20B_1'

./Sources/Application/Menu/Screen_Callbacks.o: In function `showTextField(long, int, unsigned long, unsigned long)':

C:\M2\Debug/../Sources/Application/Menu/Screen_Callbacks.cpp:143: undefined reference to `WM_GetDialogItem'

C:\M2\Debug/../Sources/Application/Menu/Screen_Callbacks.cpp:144: undefined reference to `TEXT_SetBkColor'

C:\M2\Debug/../Sources/Application/Menu/Screen_Callbacks.cpp:145: undefined reference to `TEXT_SetTextColor'

./Sources/Application/Menu/Screen_Callbacks.o: In function `cbBkWindowCallback(WM_MESSAGE*)':

C:\M2\Debug/../Sources/Application/Menu/Screen_Callbacks.cpp:267: undefined reference to `GUI_SetBkColor'

C:\M2\Debug/../Sources/Application/Menu/Screen_Callbacks.cpp:268: undefined reference to `GUI_Clear'

0 Kudos
1,326 Views
mike1974
Contributor III

Hmm I just noticed I'm using "ObjectList" ( a text file) as the input of .o files to use.  I did this to get around the Windows command line limit (8192 chars).  I just saw this morning on mcuoneclipse.com that there is a fix for that.  I wonder if this could be causing it?

0 Kudos