I have this simple C ++ 11 code.
#include <vector>
I am trying to create this code with CMake installed on Xcode and clang ++.
This is cmakelists.txt
cmake_minimum_required(VERSION 2.8) project( testit ) set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") set(testit testit.cpp ) add_executable(gv ${testit})
clang ++ build.
- mkdir build and cd build
- export CC = / usr / bin / clang
- export CXX = / usr / bin / clang ++
- cmake ..
- to do
I could get a binary that works fine.
Xcode 4.5 Goal
- Same step 1-3
- cmake .. -G Xcode
- xcodebuild
The compilation works fine, but when I received an error in the assembly with the Undefined symbol error. I install C ++ 11 with this command in the Cmake set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") .
Undefined symbols for architecture x86_64: "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from: void std::__1::vector<std::__1::unique_ptr<A, std::__1::default_delete<A> >, std::__1::allocator<std::__1::unique_ptr<A, std::__1::default_delete<A> > > >::__push_back_slow_path<std::__1::unique_ptr<A, std::__1::default_delete<A> > >(std::__1::unique_ptr<A, std::__1::default_delete<A> >&&) in testit.o "std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(int)", referenced from: _main in testit.o "std::__1::cout", referenced from: _main in testit.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
What could be wrong?
ADDED
From this link, it seems that the target setup is incorrect with CMake's xbuildcode. http://www.executionunit.com/blog/2012/10/27/xcode-std-link-errors/
ADDED
I could fix this problem, but I had to use the same directory where CMakeLists.txt is located.
! [enter image description here] [1]
When I execute CMake .. -G XCode , I got another error.
=== BUILD AGGREGATE TARGET ZERO_CHECK OF PROJECT XcodeTest WITH THE DEFAULT CONFIGURATION (Debug) === Check dependencies PhaseScriptExecution "CMake Rules" build/XcodeTest.build/Debug/ZERO_CHECK.build/Script-BED7FB205C634C34A1ACD293.sh cd /Users/smcho/Desktop/cmake /bin/sh -c /Users/smcho/Desktop/cmake/build/XcodeTest.build/Debug/ZERO_CHECK.build/Script-BED7FB205C634C34A1ACD293.sh echo "" make -f /Users/smcho/Desktop/cmake/build/CMakeScripts/ReRunCMake.make make[1]: *** No rule to make target `/Users/smcho/Desktop/cmake/build/CMakeFiles/2.8.10.2/CMakeCCompiler.cmake', needed by `CMakeFiles/cmake.check_cache'. Stop. make: *** [/Users/smcho/Desktop/cmake/build/CMakeFiles/ZERO_CHECK] Error 2 Command /bin/sh failed with exit code 2 ** BUILD FAILED ** The following build commands failed: PhaseScriptExecution "CMake Rules" build/XcodeTest.build/Debug/ZERO_CHECK.build/Script-BED7FB205C634C34A1ACD293.sh [1]: http://i.stack.imgur.com/xHW5M.png