[CMake] Fwd: Help regarding dependency..I guess..

Michael Hertling mhertling at online.de
Thu Oct 6 00:30:57 EDT 2011


On 10/02/2011 06:41 PM, gaurav chetal wrote:
> Frndzz..
> 
> I am attaching an archive file herewith!!!..In it the ".h" file of project A
> is not able to link to the ".h" file of project B when linking the library
> of A as well as B with the executable..This is just an outline of what i
> want to execute in my project.
> 
> I am a beginner to CMake so very much confused sir..Plzz help!!!

A/CMakeLists.txt: You don't have a target named "A", so saying
target_link_libraries(A B) makes no sense; probably, you meant
target_link_libraries(utilities B) as the utilities library is
built from ProA.C that includes prob.h - probably ProB.h - via
ProA.h. File names are usually case-sensitive. Furthermore, as
main.C includes ProA.h, you probably need target_link_libraries(
t utilities). Always specify merely immediate dependencies with
target_link_libraries() and let CMake find out the mediate ones.

Moreover, in order to make target_link_libraries(utilities B) do what
you probably want, the targets B and utilities must be defined within
the same project, so you need a top-level CMakeLists.txt file next to
the directories A and B, reading roughly

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(AB CXX)
ADD_SUBDIRECTORY(A)
ADD_SUBDIRECTORY(B)

and you build the overall project from that CMakeLists.txt. In this
way, you could also use CMAKE_SOURCE_DIR in include_directories():

include_directories(${CMAKE_SOURCE_DIR}/A ${CMAKE_SOURCE_DIR}/B)

A/main.C: Where is the function toLowerCase() defined? AFAIK, it's not
in the C++ standard library, so it is not surprising that you get an
undefined reference during the link stage, and what's the object x?

Finally, never say "using namespace std;" in a *header* file.

'hope that helps.

Regards,

Michael

> On Fri, Sep 30, 2011 at 7:25 PM, Eric Noulard <eric.noulard at gmail.com>wrote:
> 
>> 2011/9/30 gaurav chetal <chetal.gaurav at gmail.com>:
>>> Respected sir!!!..
>>>
>>> Actually i have made the static libraries..But the problems which m
>> gettin
>>> is that the program of the CMakeLists.txt is first of all nt able to pick
>> up
>>> the libraries (with TARGET_LINK_LIBRARY) and second thing those libraries
>>> are of the header files (.h)..The header files also it is nt picking up
>> as a
>>> result of that!!!
>>
>> May be you can send us an archive of your sample project
>> which exhibit the issue, I suspect that the problem may not be with CMake.
>>
>> Do you manage to compile your project by hand using hand-wriiten
>> command lines?
>>
>>
>> --
>> Erk
>> Membre de l'April - « promouvoir et défendre le logiciel libre » -
>> http://www.april.org


More information about the CMake mailing list