[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    [CMake] RE: Trouble with interdependent libraries
From:       "Tal Blum" <tblum () bbn ! com>
Date:       2007-11-28 19:32:38
Message-ID: 008601c831f5$6f853ad0$13162180 () d4m ! bbn ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


This might be circular dependencies between your LibC and LibB libraries. I
had such problem where it worked on Windows but not on Linux. If this is the
case you can solve it by:

 

TARGET_LINK_LIBRARIES (A B C B)

Or

TARGET_LINK_LIBRARIES (A B C B C.)

 

I solved it by defining a library that combines both libraries to one
library and add the library file to the source files of every executable
that links against them.

 

IF(UNIX)

   # This is to overcome circular dependencies between ${BUILD_LANGUAGE} and
Generic libs.

   # the benefit of doing it this way is that the combined library is only
created once.

   SET (COMBINED_LIB ${CMAKE_BINARY_DIR}/lib${BUILD_LANGUAGE}Generic.a)

   ADD_CUSTOM_COMMAND(OUTPUT ${COMBINED_LIB}

      COMMAND ar ARGS crsv ${COMBINED_LIB} `find ./${BUILD_LANGUAGE} -name
'*.o'` `find ./Generic -name '*.o'`

      DEPENDS ${BUILD_LANGUAGE} ${GENERIC_LIBRARIES}

      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}

      COMMENT "Creating a single library from ${BUILD_LANGUAGE} & Generic"


   )

   

   # adding the library to SOURCE_FILES creates a dependency of the project
on the library.

   SET (SOURCE_FILES ${SOURCE_FILES} ${COMBINED_LIB})

ENDIF(UNIX)

 

It is not so elegant, but it works.

 

 

>I'm working with 3 CMakeLists.txt files I didn't write, so I'm trying to
figure out the reasoning behind them.

>

>-Application A has a CMakeLists.txt file with TARGET_LINK_LIBARIES(LibB,
LibC). -LibB and LibC each have their own subfolders and CMakeLists.txt
>file, and use ADD_LIBRARY to declare their sources to be a library. -LibB
uses some classes defined in LibC.

>

>Under windows, I can run cmake, compile and link without errors. On Linux,
I get linker errors that LibB's uses of LibC are undefined >references. I
tried adding TARGET_LINK_LIBRARY(LibC) to LibB's CMakeLists.txt file, but
that didn't fix the error. Any ideas?

 

 

 


[Attachment #5 (text/html)]

<html>

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">


<meta name=Generator content="Microsoft Word 10 (filtered)">

<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
span.EmailStyle17
	{font-family:Arial;
	color:windowtext;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>This might be circular
dependencies between your LibC and LibB libraries. I had such problem where it
worked on Windows but not on Linux. If this is the case you can solve it \
by:</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>TARGET_LINK_LIBRARIES (A B C
B)</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>Or</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>TARGET_LINK_LIBRARIES (A B C
B C&#8230;)</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>I solved it by defining a
library that combines both libraries to one library and add the library file to
the source files of every executable that links against them.</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>IF(UNIX)</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp; # This is to
overcome circular dependencies between ${BUILD_LANGUAGE} and Generic \
libs.</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp; # the benefit
of doing it this way is that the combined library is only created \
once.</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp; SET (COMBINED_LIB
${CMAKE_BINARY_DIR}/lib${BUILD_LANGUAGE}Generic.a)</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;
ADD_CUSTOM_COMMAND(OUTPUT ${COMBINED_LIB}</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
COMMAND ar ARGS crsv ${COMBINED_LIB} `find ./${BUILD_LANGUAGE} -name '*.o'`
`find ./Generic -name '*.o'`</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DEPENDS ${BUILD_LANGUAGE} ${GENERIC_LIBRARIES}</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
COMMENT &quot;Creating a single library from ${BUILD_LANGUAGE} &amp; \
Generic&quot;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp; </span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp; )</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp; </span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp; # adding the
library to SOURCE_FILES creates a dependency of the project on the \
library.</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp; SET (SOURCE_FILES
${SOURCE_FILES} ${COMBINED_LIB})</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>ENDIF(UNIX)</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>It is not so elegant, but it
works.</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&gt;I'm working with 3
CMakeLists.txt files I didn't write, so I'm trying to figure out the reasoning
behind them.</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&gt;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&gt;-Application A has a
CMakeLists.txt file with TARGET_LINK_LIBARIES(LibB, LibC). -LibB and LibC each
have their own subfolders and CMakeLists.txt &gt;file, and use ADD_LIBRARY to
declare their sources to be a library. -LibB uses some classes defined in \
LibC.</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&gt;</span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>&gt;Under windows, I can run
cmake, compile and link without errors. On Linux, I get linker errors that
LibB's uses of LibC are undefined &gt;references. I tried adding
TARGET_LINK_LIBRARY(LibC) to LibB's CMakeLists.txt file, but that didn't fix
the error. Any ideas?</span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>&nbsp;</span></font></p>

</div>

</body>

</html>



_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic