[CMake] Unix Makefiles/XCode not linking properly on Mac

David Cole david.cole at kitware.com
Fri Nov 14 13:47:44 EST 2008


You do not need an "add_dependencies" call after the add_executable, you
need a "target_link_libraries" to tell the exe to link in the library...

HTH,
David

On Fri, Nov 14, 2008 at 1:23 PM, Neal Meyer <nmeyer at dottedzebra.com> wrote:

> I built an extremely simple project.  Contains main.cpp, and then a library
> with widget.cpp init.  here is the CMakeLists.txt that I'm using
>
> project( c++_cmd_line )
> CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
>
> #setup the output directories
> set( LIB_OUT_DIR ${CMAKE_BINARY_DIR}/bin/lib )
> set( EXE_OUT_DIR ${CMAKE_BINARY_DIR}/bin )
> set( EXECUTABLE_OUTPUT_PATH ${EXE_OUT_DIR} )
> set( LIBRARY_OUTPUT_PATH ${LIB_OUT_DIR} )
>
> add_library( widget STATIC widget.h widget.cpp )
> add_executable( c++_cmd_line main.cpp )
>
> add_dependencies( c++_cmd_line widget )
>
>
> main.cpp is just Hello world that calls a couple made up functions in the
> widget class to get the dependencies.  And here is what the make spits out
>
> Scanning dependencies of target widget
> [ 50%] Building CXX object CMakeFiles/widget.dir/widget.cpp.o
> Linking CXX static library bin/lib/libwidget.a
> [ 50%] Built target widget
> Scanning dependencies of target c++_cmd_line
> [100%] Building CXX object CMakeFiles/c++_cmd_line.dir/main.cpp.o
> Linking CXX executable bin/c++_cmd_line
> Undefined symbols:
>   "Widget::get_i()", referenced from:
>       _main in main.cpp.o
>   "Widget::get_j()", referenced from:
>       _main in main.cpp.o
>   "Widget::Widget()", referenced from:
>       _main in main.cpp.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> make[2]: *** [bin/c++_cmd_line] Error 1
> make[1]: *** [CMakeFiles/c++_cmd_line.dir/all] Error 2
> make: *** [all] Error 2
>
> I've tried moving the build directory around and even running cmake
> directly in my source directory, but to no avail.
>
> -Neal
>
>
>
> On Fri, Nov 14, 2008 at 5:16 AM, Michael Jackson <
> mike.jackson at bluequartz.net> wrote:
>
>>
>> On Nov 13, 2008, at 7:59 PM, Neal Meyer wrote:
>>
>>  I have a project that I have been working on for a while using the Visual
>>> Studio generator in Windows, and I am now attempting to build in on Mac.
>>>  Right now it's very early and I'm having problems building any of the
>>> executables using the Unix Makefile generation or the XCode generator.  It's
>>> basically just a couple of static libraries, that need to get linked into to
>>> build the executable.  I have set them up as dependencies in the CMake
>>> files, and in XCode they show as dependencies, and the Unix builds them in
>>> the proper order.  But it doesn't appear to try to link them in via the make
>>> files.  I'm makefile illiterate so there maybe something I'm missing in
>>> them.
>>>
>>> Is there anywhere I could start to try to figure out what's wrong?
>>>
>>> -Neal
>>>
>>
>> Do you get a link error when you try to compile? Does the code compile at
>> all? Can yo post the error messages to the list?
>>
>>
>> _________________________________________________________
>> Mike Jackson                  mike.jackson at bluequartz.net
>> BlueQuartz Software                    www.bluequartz.net
>> Principal Software Engineer                  Dayton, Ohio
>>
>>
>>
>>
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081114/2c026ca7/attachment.htm>


More information about the CMake mailing list