How can I build LLVM and link it against libc++? - macos

I am trying to build LLVM and link it against libc++, but I can't get it to work. I downloaded the latest version (LLVM 3.2).
$ CXXFLAGS=-stdlib=libc++ LDFLAGS=-stdlib=libc++ ../llvm-3.2.src/configure
$ make
llvm[0]: Constructing LLVMBuild project information.
llvm[1]: Compiling APFloat.cpp for Release+Asserts build
llvm[1]: Compiling APInt.cpp for Release+Asserts build
(etcetera)
llvm[1]: Building Release+Asserts Archive Library libLLVMTableGen.a
llvm[2]: Compiling FileCheck.cpp for Release+Asserts build
llvm[2]: Linking Release+Asserts executable FileCheck (without symbols)
Undefined symbols for architecture x86_64:
"std::string::find_last_not_of(char, unsigned long) const", referenced from:
llvm::SMDiagnostic::print(char const*, llvm::raw_ostream&, bool) const in libLLVMSupport.a(SourceMgr.o)
"std::string::copy(char*, unsigned long, unsigned long) const", referenced from:
llvm::sys::Path::makeUnique(bool, std::string*) in libLLVMSupport.a(Path.o)
"std::string::find(char const*, unsigned long, unsigned long) const", referenced from:
llvm::sys::getDefaultTargetTriple() in libLLVMSupport.a(Host.o)
"std::string::find(char, unsigned long) const", referenced from:
llvm::sys::Program::FindProgramByName(std::string const&) in libLLVMSupport.a(Program.o)
(followed by a bunch of other related linker errors)
Complete output on Gist.
LLVM compiles and links fine with libstdc++, but not with libc++. I have no idea why it won't link with libc++; other programs just link fine. I am running OS X Mountain Lion and libc++ is in /usr/lib/libc++.1.dylib. The compiler used is Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn).

Trust me, I'm not expert in this area. But try this:
../llvm/configure --enable-libcpp
And in general I've found:
../llvm/configure --help
quite helpful.

Related

Xcode 6 - compile and use gtest 1.7

About a week ago I moved from Windows and Visual Studio to Mac and Xcode. I want to be able to work on my project on Mac, so I decided to port it.
First of all I need test to work on Mac and Google provides instructions about how to do so. After I build test with my Xcode, I can see three files in the output directory: test.framework, libgtest_main.a and libgtest.a.
Documentation says I need to link test.framework with my project. So, I create new console app project and link it with test.framework file.
Unfortunately my build fails with about 70+ issues. After I link librettist.a to my project, it fails with only 2 issues. Here they are:
Undefined symbols for architecture x86_64:
"testing::internal::EqFailure(char const*, char const*,
std::__1::basic_string,
std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&,
bool)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ(char const*, char const*, int const&, int const&) in main.o ld:
symbol(s) not found for architecture x86_64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
As I understood, linker cannot resolve symbols. If I link my project with libgtest_main.a it changes nothing and this error is still here. So, how can I fix it?
I had the same problem and was unable to figure out why this isn't being created. It does work fine on some 32 bit code, so I'm equally puzzled.
That said, the sample in the gtest package has the following comment:
EXPECT_EQ(expected, actual) is the same as EXPECT_TRUE((expected) ==
(actual)) except that it will print both the expected value and the
actual value when the assertion fails. This is very helpful for
debugging. Therefore in this case EXPECT_EQ is preferred.
and the same is true for ASSERT_EQ and ASSERT_TRUE. So if you make the substitution, you lose some information in the case of failure, but at least you can use it.

Google Test and XCode 4.6

Problem with google test in XCode 4.6.3
Hello all,
I have integrated google tests into my XCode project, and basic command line tool for
unit testing seems to work fine (guest.framework added, DYLD_LIBRRY_PATH set correctly).
However, as soon as I add to object fixture EXPECT_EQ(0, Object.PublicMember) type
test, I get following linker error.
Ld /Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug/UnitTest normal x86_64
cd /Users/rinkevic/Development/VeloxChemX
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug -F/Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug -F/Users/rinkevic/Development/Frameworks -F/Users/rinkevic/Development/VeloxChemX/../../Library/Frameworks -F/Users/rinkevic/Development/VeloxChemX/../Frameworks -filelist /Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Intermediates/VeloxChemX.build/Debug/UnitTest.build/Objects-normal/x86_64/UnitTest.LinkFileList -mmacosx-version-min=10.8 -stdlib=libc++ -framework gtest -framework OpenCL -o /Users/rinkevic/Library/Developer/Xcode/DerivedData/VeloxChemX-hbmvfkmcscchsvebxpaefvzmkvdp/Build/Products/Debug/UnitTest
Undefined symbols for architecture x86_64:
"testing::internal::EqFailure(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in TestCartMom.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any suggestion what I am doing wrong?
I had the same problem.
Choose libstdc++ in both projects.
It's because the build options of your unit test project is different with the gtest project.
Make sure the build options such as "Apple LLVM - Language" & "Apple LLVM - Language - C++" are all the same.
Another solution is outlined here: http://dennycd.me/google-test-xcode-mac-osx/ which brings some sanity to the situation by not using a framework but instead installing into /usr/local.
Remember that the libs must be renamed to start with 'lib', for example libgtest.a.
Also remember that you must link to both libgtest.a and libgtest_main.a. Without the latter, you will get a complaint about missing the main method.
The same comments regarding the c++ dialect and the library are applicable, but I found it very hard to control these while producing the framework and trying to link to that.
By default General.xcconfig points to 10.4 SDK, changing it to 10.10 fixed issue for me

OSX linking program: undefined symbols for x86_64

I have a program that runs correctly when using .png files.
I'm trying to convert it to support OpenEXR.
The program is compiled with macports g++-mp-4.5, and links against macports's openexr1.7.
Relevant parts of the compile line:
/opt/local/bin/g++-mp-4.5 ... -I/opt/local/include/OpenEXR -I/opt/local/include/OpenEXR file.cc ...
-L/opt/local/lib -lIlmImf -lHalf ...
When run, it does this when it tries to call the exr library:
libc++abi.dylib: terminate called throwing an exception
When it is changed to link with the .a files
/opt/local/lib/libIlmImf.a /opt/local/lib/libHalf.a
it gives a link error
Undefined symbols for architecture x86_64:
"Iex::throwErrnoExc(std::basic_string, std::allocator > const&)", referenced from:
Imf::(anonymous namespace)::writeLineOffsets(Imf::OStream&, std::vector > const&) in libIlmImf.a(ImfOutputFile.o)
Imf::StdIFStream::StdIFStream(char const*) in libIlmImf.a(ImfStdIO.o)
Imf::(anonymous namespace)::checkError(std::basic_istream >&, long) in libIlmImf.a(ImfStdIO.o)
After searching, it seems that this (*undefined symbols for x86_64*) is a common problem for linux-style mac development, and does not appear to be specific
to openexr. However after reading various posts, I still do not understand what the solution is!
Here is a post on the exact problem, however the solution is not explained in enough detail for me to understand:
http://lists.nongnu.org/archive/html/openexr-devel/2011-08/msg00007.html

Qt4.8 + CMake 2.8.5 on OSX 10.5.8 can't link

I'm using Qt4.8 on OSX Leopard and instead of qmake+QtCreator I want to compile a very simple project using CMake on OSX to understand how to do a package.
While the very same project compiles and links smoothly under Linux, under my OSX box, this is the error message I always get in the linking phase:
ld warning: in /Library/Frameworks//QtGui.framework/QtGui, file is not of required architecture
ld warning: in /Library/Frameworks//QtCore.framework/QtCore, file is not of required architecture
Undefined symbols:
"QWidget::mousePressEvent(QMouseEvent*)", referenced from:
vtable for TestFormin moc_TestForm.cxx.o
"QObject::childEvent(QChildEvent*)", referenced from:
vtable for TestFormin moc_TestForm.cxx.o
"QWidget::actionEvent(QActionEvent*)", referenced from:
vtable for TestFormin moc_TestForm.cxx.o
"QCoreApplication::translate(char const*, char const*, char const*, QCoreApplication::Encoding)", referenced from:
etcetera etcetera.
This happens for every project I want to compile with cmake.
Any idea of what's going on?
Check what architecture (i386,x86_64) is being used by cmake (CMAKE_OSX_ARCHITECTURES). Try suggesting the architecture to cmake:
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64

WxWidgets / GCC / MacOs X: How can I build and link the WxWidgets library properly?

I am trying to port a windows application based on WxWidgets 2.8.9 to MacOS X. I've gotten to the point where everything compiles successfully, except from a few missing symbols related to WxWidgets. I've tried compiling WxWidgets with the command line and with XCode and I've tried several different configuration options, but none of this has worked properly. The WxWidgets Wiki has a few articles about this here, but most of the information is outdated and none of it solved my problem.
The closest I got was by compiling WxWidgets at the command line with
./configure --enable-monolithic
make
Then I linked the library by adding "wxMac-2.8.9/lib/libwx_mac-2.8.a" to the "Other Linker Flags" in my XCode project settings.
But this gives me the following linking errors:
"wxOnAssert(char const*, int, char const*, char const*, char const*)", referenced from:
wxStringBase::wxStringBase(wxStringBase const&)in MyFrame.o
wxCloseEvent::Veto(bool) in MyFrame.o
wxStringBase::wxStringBase(wxStringBase const&)in TGameSettingsForm.o
wxCheckBoxBase::DoSet3StateValue(wxCheckBoxState) in TGameSettingsForm.o
wxCheckBoxBase::DoGet3StateValue() const in TGameSettingsForm.o
wxStringBase::wxStringBase(wxStringBase const&)in NonoGameStates.o
wxStringBase::wxStringBase(wxStringBase const&)in TWxInvalidRegCodeForm.o
"_iconv_close", referenced from:
wxMBConv_iconv::~wxMBConv_iconv()in libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::~wxMBConv_iconv()in libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::~wxMBConv_iconv()in libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::~wxMBConv_iconv()in libwx_mac-2.8.a(monolib_strconv.o)
"wxAppConsole::OnAssert(char const*, int, char const*, char const*)", referenced from:
vtable for CMyWxApp3_wxstaticAppin MyWxApp3-wxstaticApp.o
"_iconv", referenced from:
wxMBConv_iconv::GetMBNulLen() const in libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::WC2MB(char*, wchar_t const*, unsigned long) constin libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::WC2MB(char*, wchar_t const*, unsigned long) constin libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::MB2WC(wchar_t*, char const*, unsigned long) constin libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::MB2WC(wchar_t*, char const*, unsigned long) constin libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::wxMBConv_iconv(char const*)in libwx_mac-2.8.a(monolib_strconv.o)
"wxAppConsole::OnAssertFailure(char const*, int, char const*, char const*, char const*)", referenced from:
vtable for CMyWxApp3_wxstaticAppin MyWxApp3-wxstaticApp.o
"_iconv_open", referenced from:
wxMBConv_iconv::wxMBConv_iconv(char const*)in libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::wxMBConv_iconv(char const*)in libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::wxMBConv_iconv(char const*)in libwx_mac-2.8.a(monolib_strconv.o)
wxMBConv_iconv::wxMBConv_iconv(char const*)in libwx_mac-2.8.a(monolib_strconv.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
If possible, I would prefer dynamic linking, not static linking as used above. However, for the moment I would be happy to get it running at all. If anyone could give me (or point me to) a working step-by-step description on how to compile and link the WxWidgets library, I would be very thankful.
Thanks,
Adrian
I've not built wx under MacOS, but I do use it extensively under Windows and Linux. The instructions on the page you linked look very similar to those under Linux and it says:
Following make, you will find the
built library under your folder (eg,
build-release). This is also where the
corresponding wx-config is.
The wx-config script under Linux makes building projects a breeze, you simply use the command wx-config --cxxflags to get the compilation flags required for gcc and wx-config --libs to get all of the required libraries for linking. Under build environments such as Code::Blocks you can use those commands in the project settings, however I am not familiar with XCode - but worst case you just need to copy the compiler and linker options that the wx-config script lists.
wxOnAssert-related errors mean that you build your library in debug (__WXDEBUG__ defined, NDEBUG is not) while wxWidgets libraries were built in release build (__WXDEBUG__ not defined). The solution is simple: don't do this.
If you need to build a debug version, build wxWidgets in debug mode too using --enable-debug configure argument and use wx-config --debug ... to get the appropriate flags.

Resources