Author Topic: ld and build options  (Read 4267 times)

Offline alle_meije

  • Multiple posting newcomer
  • *
  • Posts: 29
ld and build options
« on: June 13, 2012, 11:27:09 am »
Hi

My project uses the fftw library for fast fourier transforms. I compile it in a separate project, with Debug and Release builds, and link the Debug build of fftw to the Debug build of my project and the Release build of fftw to the Release build of my project.

All works fin when I to have it set like this:
(1)
   Build Options
      main -
      Debug - Linker settings - Link libraries: ../fftw/Bin/Debug/libfftw.so
      Release - Linker settings - Link libraries: ../fftw/Bin/Release/libfftw.so

It seems more elegant though to do it like this:         
(2)
   Build Options
      main - Linker settings - Link libraries: libfftw.so
      Debug - Search directories - Linker: ../fftw/Bin/Debug
      Release - Search directories - Linker: ../fftw/Bin/Release

Building it with method (2) fails though, with the familiar error
/usr/bin/ld: cannot find -lfftw.so
collect2: ld returned 1 exit status

So does method (2) just not work? Do linker search directories work differently from compiler search directories?

best wishes
Alle Meije

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: ld and build options
« Reply #1 on: June 13, 2012, 11:56:51 am »
You should add "fftw" to your linker settings - link libraries, but NOT "libfftw.so"
Regards,
xunxun

Offline alle_meije

  • Multiple posting newcomer
  • *
  • Posts: 29
Re: ld and build options
« Reply #2 on: June 13, 2012, 01:19:53 pm »
That works! Thanks very much, I wouldn't have found that myself.

So in short
* when you supply the full path in 'Link libraries', you put fullpath/libNAME.so
* when you supply the path in 'Search directories', you put NAME in 'Link libraries'

This helps a lot! Only running from the main project dir (or else getting errors like /bin/Release/libbfftw.so: cannot open shared object file) was getting a bit cumbersome...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: ld and build options
« Reply #3 on: June 13, 2012, 02:01:16 pm »
Thanks very much, I wouldn't have found that myself.
That's why I always suggest before using any IDE, compile at the command line to understand the compiler/linker interface. Than setting up your project in an IDE is a snap.

Its like running a garage w/o having ever driven a car otherwise.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ