[CMake] how to link with a system library ?

Mike Jackson mike.jackson at bluequartz.net
Sun Sep 21 10:11:01 EDT 2008


On Sep 21, 2008, at 10:02 AM, Steven Samuel Cole wrote:

> Mike Jackson schrieb:
>> On Sep 21, 2008, at 9:28 AM, Steven Samuel Cole wrote:
>>> Mike Jackson schrieb:
>>>> include(FindGTK)
>>>> add_executable (myexec ${sources} )
>>>> target_link_libraries(myexec ${GTK_LIBRARIES} )
>>>> Note the order above.
>>>> Also, cmake variables are ALWAYS used with braces ${Variable} NOT  
>>>> $Variable.
>>>> Mike
>>>
>>> Thanks for that, Mike :-)
>>>
>>> The sample code corresponds to what I'm doing, even the order  
>>> happens to be the same. I still keep getting GTK include errors.  
>>> Tried include_directories (... ${GTK_INCLUDE_DIR}) in all orders.
>>>
>>> BTW: Why does the order matter ? How do I know the right order ?
>>>
>>> When I use hand-coded include paths, I get GTK linker errors.
>>>
>>> > If you are having cmake generate makefiles then run make in the
>>> > following fashion:
>>> >
>>> > make VERBOSE=1
>>> >
>>> > and carefully inspect the compile line. From that you should be  
>>> able
>>> > to deduce why gtk/gtk.h is NOT on the  include paths.
>>>
>>> True,there is nothing GTK-related in the compile line.
>>>
>>> So does FindGTK silently fail to find GTK inc/libs ?
>>> If so, how can I fix that ?
>>>>
>> You need to "add_executable" before you can  
>> "target_link_libraries". The add_executable command adds a "target"  
>> called myexec. Then you "target_link_libraries". Think of the  
>> "add_executable" as the compile step and the  
>> "target_link_libraries" as the link step. You have to compile  
>> before you can link. ;-)
>> Looking at the FindGTK module in CMake 2.6.1 it would seem that it  
>> will silently fail. add the following to your cmake code:
>> FIND_PACKAGE(GTK REQUIRED)
>> IF (NOT GTK_FOUND)
>>   MESSAGE (FATAL_ERROR "GTK NOT FOUND")
>> ENDIF (NOT GTK_FOUND)
>> then your add_executable and target_link_libraries lines and lets  
>> see what happens
>> ---
>> Mike Jackson - Principal Software Engineer
>> www.bluequartz.net
>
> CMake Error: GTK NOT FOUND
> -- Configuring done
> make: *** [cmake_check_build_system] Error 255
>
> GTK 2.0 comes into my Kubuntu 8.0.4 system with a standard debian  
> package. Nothing customized. All in standard paths.

I don't know a thing about GTK BUT looking at the FindGTK.cmake file  
in the CMake 2.6 distribution it _looks_ like that module is looking  
for the gtk 1.2 version and NOT the 2.0 version.

Can you tell me the following:
  What is the complete path to the gtk.h file you are wanting to  
include?
  What is the complete pat to the main gtk library (including full  
filename) for gtk?

That will help with the next step.

Mike



More information about the CMake mailing list