Problems linking static library

Hi all, I’m having an issue trying to link a static library in Juce. I’ve managed to get it working in core C++ (XCode) by adding the Accelerate, CoreAudio, and CoreAudioKit frameworks along with my lib in the build phases setting in XCode, then bringing the lib and it’s corresponding .h into the file explorer.

I tried to repeat this process in Juce (and even tried doing the same process alone in XCode, knowing it won’t save) and I still get linker errors. I tried linking it using the extra compiler flags and linker flags, the external libraries to link, and extra library search paths. In short I’ve tried everything…

Wondering if there’s anyone that can help? Much appreciated!

For me it works like that:

  • additional include flags: -Ipath/to/include
  • additional linker flags: -Lpath/to/lib
  • external libraries to link: name without .a .so or .lib, the projucer will add that



1 Like

Hey Daniel, thanks for your help. Unfortunately it’s still not working for me. Here’s what I have:

Here’s the lib itself:

Here’s how I’ve set it up in the Projucer:

Still not finding the lib:

Thanks for your help!

Yeah, the linker has it’s own search path, and it is fed by -L as linker flag. You can see it in the linker call e.g. -L/Users/djatwar/Development/JUCE/ScratchEZ/scratchGameCPP/Builds/MacOSX/build/Debug

Option 1: quick and dirty copy the lib there (bad idea, because no manual steps should be necessary in the build folder, but works)
Option 2: add the path to the libVinylTrack.a file with -L in Extra linker flags. You can add any number of paths using -L for each folder

It is a bit tricky though to get the relative paths right, that’s why I use something like -L${PROJECT_DIR}/../SDK. If you use simply relative paths, I think it is relative to the xcodeproj file IIRC.

I just notice you use round brackets for PROJECT_DIR, I think there should be curly brackets.

Good luck

Thanks. I’ve got the relative path right with -L in extra linker flags, but it’s still saying that it hasn’t found the library. So strange!

Is it possible that I need to somehow add the coreaudiokit framework again to make this work, as I did before when I got it working in core c++?

Ok, two more checks:

  • does the correct path appear in the call to the linker? It could be, that some type error, or Projucer save sequence was not 100%
  • add -static to the extra linker flags. I thought it would try that automatically, if no .so was found, but maybe you need to say explicitly, that you want a static link…

If your library depends on coreaudiokit, then yes. But that would have been unresolved symbols later on. At the moment the linker doesn’t see your libVinylTrack.a

Oh, I just see: don’t put libVinylTrack into the libraries to link. The prefix lib is also automatically added, just put VinylTrack and the linker will search for and if not found for libVinylTrack.a. When using the -static it will search for the .a only (or prefer .a? IDK)

It works!!! You were right I just had to take “lib” off the front of the name. Didn’t need to use -static. Thanks again Daniel :smiley:

Can someone tell me where the PROJECT_DIR points to? I’ve been trying to do the same but it doesn’t work…

It is the directory, where your IDE project file is (not the jucer file!)
For XCode it is ./Builds/MacOSX/, for VS2019 it is .\\Builds\\VisualStudio2019 etc.

Hi @daniel,

I’ve run into the same issue and I’ve implemented all the advice you’ve given but still no dice. Been tearing my hair out over this for hours and I’d be so grateful if you had any more suggestions.

Here’s where I’m at in the projucer:

With the -static flag shown in ‘Extra Linker Flags’ above, I get the linker error:

ld: library not found for -lcrt0.o

Without the -static flag I get a long list of errors of the form:

duplicate symbol '*variable*' in:

Do you have any idea what’s going on? Not sure if this is fftw specific, when I try to include fftw3f in the ‘External Libraries to Link’ section for floating point precision I get the same error(s).

I think the problem is, that -static makes all following libs in the link command treated static. So it sounds to me like crt0 is only available as shared library. If assembling the build command manually, you would revert the setting back using -shared. But I am terribly bad with build systems, so I don’t know what to advise here.

Ok no worries, will keep trying and post if anything comes up. Thanks again @daniel

Hi all, I’m trying to link a static copy of the FFTW library with the proJucer to build in my project but I keep getting linking errors and can’t seem to resolve them.

Things I’ve done:
I’ve downloaded and moved the contents of the FFTW library to a folder in my project called fftw
I’ve added that to the file explorer

 I then added the header paths and such

And I have enabled the use of the static FFTW library in the DSP module

but i am still getting linking errors :frowning:

Any help is greatly apreciated

Update - Fixed: Seem to have fixed the issue by setting the JUCE_DSP_USE_STATIC_FFTW field in the juce_dsp module to false. Everything is working now and i can use the FFTW library however I don’t know if this is the correct approach.

I don’t fully understand what the JUCE_DSP_USE_STATIC_FFTW field is doing and if anyone could give an explanation id be very grateful.