[CMake] Cannot compile simple example using cmake and xcode (linker problem)

Pim Schellart P.Schellart at student.science.ru.nl
Mon Jun 22 06:08:22 EDT 2009


Hello Everyone,

I would like to compile a cmake project using Xcode.
But compiling even a simple test project fails on my system.
I tried to compile the example using standard make (with cmake
generated Makefiles) and it works.
But if I generate an Xcode project using cmake -G Xcode, open this
project and click build I get build failed with the following errors:

Building target “test” of project “Test” with configuration “Debug” — (7 errors)
	    mkdir /Users/pim/Temp/test/Debug
    cd /Users/pim/Temp/test
    "/Developer/Library/Xcode/Plug-ins/GCC
4.0.xcplugin/Contents/Resources/cc" -arch i386
-L/Users/pim/Temp/test/Debug -F/Users/pim/Temp/test/Debug -filelist
/Users/pim/Temp/test/Test.build/Debug/test.build/Objects-normal/i386/test.LinkFileList
-Wl,-search_paths_first -headerpad_max_install_names -o
/Users/pim/Temp/test/Debug/test
Undefined symbols:
  "___gxx_personality_v0", referenced from:
      ___gxx_personality_v0$non_lazy_ptr in test.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)", referenced from:
      __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_$non_lazy_ptr
in test.o
  "std::ios_base::Init::~Init()", referenced from:
      ___tcf_0 in test.o
  "std::basic_ostream<char, std::char_traits<char>
>::operator<<(std::basic_ostream<char, std::char_traits<char> >&
(*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced
from:
      _main in test.o
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)", referenced from:
      _main in test.o
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int)in test.o
  "std::cout", referenced from:
      __ZSt4cout$non_lazy_ptr in test.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
		  "___gxx_personality_v0", referenced from:
		      ___gxx_personality_v0$non_lazy_ptr in test.o
		  "std::basic_ostream<char, std::char_traits<char> >&
std::endl<char, std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)", referenced from:
		      __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_$non_lazy_ptr
in test.o
		  "std::ios_base::Init::~Init()", referenced from:
		      ___tcf_0 in test.o
		  "std::basic_ostream<char, std::char_traits<char>
>::operator<<(std::basic_ostream<char, std::char_traits<char> >&
(*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced
from:
		      _main in test.o
		  "std::basic_ostream<char, std::char_traits<char> >&
std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)", referenced from:
		      _main in test.o
		  "std::ios_base::Init::Init()", referenced from:
		      __static_initialization_and_destruction_0(int, int)in test.o
		  "std::cout", referenced from:
		      __ZSt4cout$non_lazy_ptr in test.o
		ld: symbol(s) not found
		collect2: ld returned 1 exit status
Build failed (7 errors)

I use the latest versions of cmake (2.6-patch 4) and Xcode (3.1.3).

The CMakeLists.txt file looks like:

project (Test)

add_executable (test test.cpp)

And the test.cpp file contains:

#include <iostream>

int main()
{
    std::cout<<"Hello World"<<std::endl;
}

Does anyone have any idea what is going wrong here?

Kind regards,

Pim Schellart


More information about the CMake mailing list