xCode linker problem


#1

Hi.

I have trouble linking an application against a static library in xcode. The static library is created with the introducer and uses some juce functions internally. I've created a small test library and it has the same problems. Here's what I did:

1. created a static library project with juce. It just has one function:

#include "test.h"
#include "juceHeader.h"
const char * testfunction() {
  juce::String test("test");
  return test.toRawUTF8();
}

2. compiled the library without errors. 

3. created a project for a console application in xcode. In build phases I added my library to "link binary with libraries". It shows up in the project and the path is added to the search path. 

4. Added some code to test:

#include <iostream>

extern const char * testfunction();

int main(int argc, const char * argv[]) {
  std::cout << testfunction() << std::endl;
  std::cin.get();
  return 0;
}

5. When compiling this, i get:

Undefined symbols for architecture x86_64:

  "_CFArrayGetValueAtIndex", referenced from:

      juce::SystemStats::getDisplayLanguage() in libNewProject.a(juce_core.o)

  "_CFLocaleCopyCurrent", referenced from:

      juce::SystemStats::getUserLanguage() in libNewProject.a(juce_core.o)

      juce::SystemStats::getUserRegion() in libNewProject.a(juce_core.o)

  "_CFLocaleCopyPreferredLanguages", referenced from:

      juce::SystemStats::getDisplayLanguage() in libNewProject.a(juce_core.o)

... and a lot more of those. Compiling libraries for windows and android works just fine. I'm not a frequent mac user though. Maybe I'm missing something? (I did check that the library as well as the test app are compiled for x86_64. ) I also verified with:

nm -gU libNewProject.a | grep 'getDisplayLanguage'

and the library has this symbol:

000000000005f020 T __ZN4juce11SystemStats18getDisplayLanguageEv

Any help on this would be great. I'm completely clueless about what is wrong.


#2

I've nothing helpful to add about your linker error, but be careful: your testFunction has a bug, it returns the address of a dangling pointer.


#3

Ok, my mistake. I was just trying to come up with a very basic example. I don't use juce::String in my real project, but the problem is the same: All my own functions and classes are found, but not the juce classes I use internally. 

Another thing i just noticed with the real library (not the example above) is that it's only 6 Mb. When compiled with visual studio it's about 136 Mb. So unless the mac version of juce is using a lot more system libraries and less internal ones compared to the windows version, something seems wrong with including the juce code in the library.

 


#4

It's the Apple CoreFoundation functions that your error list says are missing, not the juce ones.


#5

Indeed, I just realized that. I not only have to link against my library, but also against all frameworks that are mentioned in the juce_module_info file of all modules that are in use by my library.

A bit of googling teaches me that it's not possible to link the frameworks to the library itself. So every project which uses the library has to include the frameworks. That will be a maintenance problem, i guess. Can't be helped though.

That might be good info of someone else attempts to create a library based on juce. (Frequent mac users might do this by intuition, but I never use my mac for anything else than compiling projects which I created on windows or linux :-)

Thanks for the help. 

 


#6

Well, that's why we have the Introjucer to handle all the library dependencies and generate the project files.. Obviously if you're going off-piste then it's up to you to understand and handle all that stuff :)


#7

You're right, of course. But the whole point of creating libraries is of course that they will be used in other projects, not necessarily juce projects. But my remark was not meant as a criticism towards juce. Juce has saved me LOTS of time already. 

I'd blame apple for always doing things different, again. On other platforms the there aren't any dependencies at all.