[CMake] Linking problems

Alexander Neundorf a.neundorf-work at gmx.net
Thu Apr 16 15:53:18 EDT 2009


On Thursday 16 April 2009, John Dey wrote:
> Hi List,
>
> I am getting undefined symbols while linking up a program that I can
> create by hand (details shown below).  I think I have set cmake to
> duplicate but it can't find symbols.  Any help would be greatly
> appreciated.  Thanks.
>
> John
>
> Hand compile and link:
>
>
> g++ -O3 -Wall -g -D__GXX__  -D__LITTLE_ENDIAN__  -D__MACOSX_CORE__ -c
> Stk.cpp -o Release/Stk.o
> g++ -O3 -Wall -g -D__GXX__  -D__LITTLE_ENDIAN__  -D__MACOSX_CORE__ -c
> MidiFileIn.cpp -o Release/MidiFileIn.o
> g++ -O3 -Wall -g -D__GXX__  -D__LITTLE_ENDIAN__  -D__MACOSX_CORE__ -c
> RtMidi.cpp -o Release/RtMidi.o
> g++ -O3 -Wall -g -D__GXX__  -D__LITTLE_ENDIAN__  -D__MACOSX_CORE__ -o
> playsmf playsmf.cpp Release/Stk.o Release/MidiFileIn.o Release/
> RtMidi.o -lpthread -lm  -framework CoreAudio -framework CoreFoundation
> -framework CoreMidi
>
> CMakeLists.txt:
>
> project (playsmf)
> cmake_minimum_required(VERSION 2.6)
> add_definitions(-D__LITTLE_ENDIAN__ -D__MACOS_CORE__ -D__GXX__ -g -
> Wall -03)


You mean "-O3", not "-03", right ?


> include_directories("${PROJECT_SOURCE_DIR}")
> add_executable(playsmf playsmf.cpp MidiFileIn.cpp RtMidi.cpp Stk.cpp)
> find_library(COREAUDIO CoreAudio "/usr")
> find_library(COREFOUNDATION CoreFoundation "/")
> find_library(COREMIDI CoreMidi "/")
> find_library(PTHREAD pthread "/")
> find_library(M m "/")
> target_link_libraries(playsmf ${COREAUDIO} ${COREFOUNDATION}
>                       ${COREMIDI} ${PTHREAD} ${M}
> )
>
> Error messages:
>
> Linking CXX executable playsmf
> Undefined symbols:
>    "RtMidiOut::initialize()", referenced from:
>        RtMidiOut::RtMidiOut()in RtMidi.cpp.o
>    "RtMidiOut::sendMessage(std::vector<unsigned char,
> std::allocator<unsigned char> >*)", referenced from:
>        _main in playsmf.cpp.o
>        _main in playsmf.cpp.o
>    "vtable for RtMidiOut", referenced from:
>        __ZTV9RtMidiOut$non_lazy_ptr in RtMidi.cpp.o
>    "vtable for RtMidiIn", referenced from:
>        __ZTV8RtMidiIn$non_lazy_ptr in RtMidi.cpp.o
>    "RtMidiIn::initialize()", referenced from:
>        RtMidiIn::RtMidiIn()in RtMidi.cpp.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> make[2]: *** [playsmf] Error 1
> make[1]: *** [CMakeFiles/playsmf.dir/all] Error 2
> make: *** [all] Error 2

Can you please post the output of "make VERBOSE=1" so we can see the actual 
link command ?

There seems to be a problem with RtMidi.cpp. I guess the functions which it 
doesn't find do indeed exist in RtMidi.cpp ?

Alex
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list