0

I've been working for a while with the gtest unit testing library for a while. Recently I set up a new development machine and upgraded to Mac OS X 10.9. I installed

brew tap homebrew/versions
brew install [flags] gcc48

I built gtest locally with

cmake .
make

and it produced libgtest.a.

The second dependency of my project is the logging library log4cxx. I got it as usual with:

brew install log4cxx

All that looks fine. But when I try to compile now, I get this massive linker error about undefined symbols which I cannot interpret. Any ideas?

clstaudt
  • 21,436
  • 45
  • 156
  • 239

2 Answers2

2

This issue relates to the use of -stdlib= when compiling. I cannot tell you which value (libstdc++ or libc++) is the correct one to use, but it has to match the one used by the libraries when they were compiled.

I guess you'll need to dig through the homebrew logs to find out.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • I've narrowed down the error to log4cxx. Homebrew uses clang to compile log4cxx while I use gcc-4.8 to compile my project. Is this the reason for the error? What can I do to change this? – clstaudt Nov 12 '13 at 22:41
  • @cls Yes that will be the problem. You should use `clang` with `-stdlib=libc++` flag to compile your project. – trojanfoe Nov 13 '13 at 06:37
  • I believe clang has no OpenMP support. If this is true, I am stuck with GCC for my project. Isn't there a way switch the compiler for `log4cxx` to GCC? – clstaudt Nov 13 '13 at 09:55
  • @cls I don't use homebrew (I prefer macports), so I don't know. I would expect so, however. – trojanfoe Nov 13 '13 at 09:56
0

The other trick to look at is to make sure that everything you are compiling is using the same -mmacosx-version-min value for all of your executable units that you are linking together. If you don't define one, Mavericks will use 10.9 and it appears to link with libc++ by default, while if you use -mmacosx-version-min=10.8 or lower it will link with libstdc++ by default.

This will give you a mismatch where some of your symbols are std::__1::foo and some are std::foo when you run them through c++filt.

dmaclach
  • 3,403
  • 1
  • 21
  • 23
  • Hmmm, that doesn't sound right (the bit about the default library used depending on which `-mmacosx-version-min` is specified). – trojanfoe Nov 14 '13 at 15:54
  • To expand on my last comment, the modern C++ runtime library (`libc++`) is supported in 10.7+, so I would not expect the behaviour you describe. – trojanfoe Nov 14 '13 at 15:58
  • "make sure that everything you are compiling is using the same -mmacosx-version-min" - how would I do that for clang and for gcc? log4cxx does not seem to compile with gcc, so I need to use clang for the library, and I need to use gcc for my project. – clstaudt Nov 14 '13 at 16:36
  • trojanfoe: We ran into this when we upgraded a machine from 10.8 to 10.9 and all of a sudden builds started failing. We had one library that had "-mmacosx-version-min=10.6" and the other library didn't have a "-mmacosx-version-min" setting so defaulted to 10.9. The one with -macosx-versions-min set to 10.6 used std::foo, and the one using 10.9 used std::__1::foo (as described [here](http://stackoverflow.com/questions/8454329/why-cant-clang-with-libc-in-c0x-mode-link-this-boostprogram-options-examp)) – dmaclach Nov 14 '13 at 18:21
  • cls: I'm not sure when you are mixing gcc and clang. Is clang defaulting to C++11? What happens if you turn that off. – dmaclach Nov 14 '13 at 18:22