0
0

What is the proper method for linking static libraries to our application’s code during the build phase? I originally looked at the app’s Makefile (by example, in the fsw/for_build directory of the app), where I would supply the linker flags in LOCAL_COPTS (where they would be placed first), or after SOURCES (to force the flags to appear last). Both of these options, however, have caused CFS to halt with an error: symbol lookup error: ./cf/apps/myApp.so: undefined symbol: someSymbol

When examining the output of make, I see that these flags only appear during the app’s compilation step, rather than the linking step where they need to be. Thus, it seems I need to modify something other than the app’s Makefile in order to link the static library. In what file would I put these flags? Would it be in $MISSION/build/cfe.mak?

Any insights would be extremely useful.

For reference, I need to pass both the static library libcsp.a and -lpthread as if it were the following (compile and link in one step, confirmed works as separate executable):

gcc $(INCLUDES) $(SOURCES) libcsp.a -lpthread

  • You must to post comments
0
0

I ran into this same issue, so I’ll put my solution here for anyone else that needs to do this.

For reference, the make chain for an app is:

cpu1 Makefile -> cfs.mak -> app Makefile -> cfe-core/src/make/app-rules.mak

Then from there the linker is called, and the linker command is in psp/fsw/pc-linux/make/link-rules.mak.

Since there is no customization available to add linked libraries, we need to add it ourselves with a psp level modification.

Change the application link rule in link-rules.mak to

$(APPTARGET).$(APP_EXT): $(OBJS)
$(COMPILER) -m32 -shared $(APP_LIBS) -o $@ $(OBJS)

and then add

APP_LIBS = -lsomelib

to your application makefile (in apps/(appname)/fsw/for_build, NOT in the build folder), do a make realclean and make config and your application should be linking the library as you’d expect.

  • mikalyawhiteaker
    Hi! I am new to CoreFlight and am trying to build an app that uses an external library. I am running into this symbol lookup error. I followed the solution above and changed the link rules and my application’s Makefile. However, I am still getting the same symbol look up error. I am wondering if this solution was used to link a static library, and if so was the .a file located anywhere within cFE? Thanks!
  • chuffine
    The library I’m using is a dynamically linked .so, stored in the standard /usr/lib folder. I believe it should work the same way using a static library, as long as your linker can find it.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.