[CMake] Question about add_custom_command

Michael Wild themiwi at gmail.com
Mon Sep 13 09:22:58 EDT 2010


On 13. Sep, 2010, at 14:57 , David Aldrich wrote:

> Hi Michael
> 
> 
>> You never link static libraries. They are more like zip files than actual
>> libraries and just contain the compiled object files and for if you ran
>> ranlib on it, also a "table-of-contents" to speed link up.
>> 
>> If you do "target_link_libraries" in CMake, where the target is a static
>> library, CMake just creates the static library archive and remembers
>> internally the transitive link dependency. If you linked that static
>> archive into an executable, the python libraries would then show up on the
>> command line.
> 
> Now I am confused (more than before!) because linking my Kernel library does give errors related to Python:
> 
> Linking CXX executable main
> CMakeFiles/main.dir/Kernel.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
> Kernel.cpp:(.text+0x101): undefined reference to `_Py_NoneStruct'
> Kernel.cpp:(.text+0x10d): undefined reference to `_Py_NoneStruct'
> 
> The make file is evidently building an executable even though I have only specified:
> 
> add_library( Kernel STATIC ${SRCS} )
> 
> I can see from make VERBOSE=1, that it is trying to link main.exe instead of calling 'ar' to build libKernel.a.
> 
> Can you give me some more help on this please?
> 
> David

Can you show above link command with "make VERBOSE=1"? I assume you do something like this?

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})

add_library(Kernel STATIC a.c b.c d.c)
target_link_libraries(Kernel ${PYTHON_LIBRARIES})

add_executable(main main.c)
target_link_libraries(main Kernel)


Michael

--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100913/d508d271/attachment.pgp>


More information about the CMake mailing list