Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » CDT » Cannot Link Sub Libraries(Cannot Link Sub Libraries)
Cannot Link Sub Libraries [message #809634] Tue, 28 February 2012 23:10 Go to next message
Steve Visser is currently offline Steve Visser
Messages: 2
Registered: February 2012
Junior Member
Hi,

This seems like a simple problem, but after trying for 2 days I still can't seem to get this to work, so any help will be greatly appreciated!

I am using codesourcery to program stellaris uc's and I cannot seem to build any projects that link with static libraries that are more than one library deep.

To try and solve the problem I have re-created my scenario in it's simplest form.

I have created a static library "AAASubLibrary". In this library is a source and header file with only one function "subLibInc()" which increments an integer.

I have created another static library "AAMainLibrary". In this library is a source and header file with only one function "mainLibInc()" which increments an integer by calling subLibInc.

Finally I have created a main program in a project called AAMainProgram. The program is a infinite loop that increments a number by calling mainLibInc();

I can build the AAASublibrary Project and the AAMainLibrary projects with no errors.
But if I call mainLibInc(); in the main program then I get a linker error.

'Building target: AAMainProgram'
'Invoking: Sourcery CodeBench C Linker'
arm-stellaris-eabi-gcc -L"C:\Users\Stevo\workspace\AAASubLibrary\Debug" -L"C:\Users\Stevo\workspace\AAMainLibrary\Debug" -Xlinker -Map="AAMainProgram.map" -T lm3s9b92-ram-hosted.ld -o "AAMainProgram" "@objs.rsp" "@user_objs.rsp" "@libs.rsp"
C:\Users\Stevo\workspace\AAMainLibrary\Debug\libAAMainLibrary.a(AAMainLibrary.o): In function `mainLibInc':
C:\Users\Stevo\workspace\AAMainLibrary\Debug/../AAMainLibrary/AAMainLibrary.c:13: undefined reference to `subLibInc'
collect2: ld returned 1 exit status
cs-make: *** [AAMainProgram] Error 1


what's wierd for me is if I replace mainLibInc(); in the main program with subLibInc(); then everything compiles fine.

Attached is a screen shot showing the results from my build.
Also attached are the source and headerfiles.

Any tips on how I can get the linker to see the sublibrary?

Cheers,

Stevo
  • Attachment: LinkerProbs.zip
    (Size: 41.17KB, Downloaded 50 times)
  • Attachment: Linker.jpg
    (Size: 362.39KB, Downloaded 54 times)
Re: Cannot Link Sub Libraries [message #809752 is a reply to message #809634] Wed, 29 February 2012 03:04 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1829
Registered: July 2009
Senior Member
The ordering of the libraries is important. AAMainLibrary needs symbols from AAASubLibrary.

Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Cannot Link Sub Libraries [message #809918 is a reply to message #809752] Wed, 29 February 2012 07:42 Go to previous message
Steve Visser is currently offline Steve Visser
Messages: 2
Registered: February 2012
Junior Member
Wow! Thanks a million Axel!

This has been killing me for days,.. and for something so simple!
I swapped the order of the include libraries and I am good to go.

Cheers and thanks for your help.

Stevo
Previous Topic:How to customize C Compare Viewer?
Next Topic:Showing coding errors and tips in Eclipse C++ Perspective
Goto Forum:
  


Current Time: Sun May 26 03:24:37 EDT 2013

Powered by FUDForum. Page generated in 0.02729 seconds