On Sat, Mar 14, 2009 at 10:43 AM, Kermit Mei <span dir="ltr">&lt;<a href="mailto:kermit.mei@gmail.com">kermit.mei@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello, I have a library which had been installed into my system<br>
under /usr/lib/. When I manually compile it, I must type:<br>
cc -Wall udpcli.c -o cli -lapue<br>
<br>
Now, I wrote my cmakelists.txt like this:<br>
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)<br>
PROJECT(UDPCS)<br>
FIND_LIBRARY(APUE_LIB, /usr/lib/)<br>
ADD_EXECUTABLE(serv udpserv.c)<br>
ADD_EXECUTABLE(cli udpcli.c)<br>
TARGET_LINK_LIBRARIES(cli, ${APUE_LIB})<br>
<br>
And then I encounter the following errors:<br>
$ cmake -DBUILD_TYPE=debug ..<br>
CMake Error: Attempt to add link library &quot;/usr/lib/libapue.so&quot; to target<br>
&quot;cli,&quot; which is not built by this project.<br>
-- Configuring done<br>
<br>
How can I settle it? <br></blockquote><div><br>The code above has many problems with it.  For one, there should be no commas.  Secondly, your find_library() call is missing the name of the library, it instead contains a directory name.  I believe you can use full paths to libraries in the find_library() call for the library name, however this is generally a bad idea.  You should read the documentation for find_library() to understand how it works.  &quot;/usr/lib&quot; is searched automatically as it is a system path.  Usually all that&#39;s needed is the library name (without the &quot;lib&quot; part).<br>
<br>The error message you mention most commonly happens when you call target_link_libraries() prior to calling add_executable() or add_library().  I suspect that&#39;s what you did.<br><br>Here&#39;s what you probably want:<br>
<br>CMAKE_MINIMUM_REQUIRED(VERSION 2.6)<br>
PROJECT(UDPCS)<br>
FIND_LIBRARY(APUE_LIB apue)<br>
ADD_EXECUTABLE(serv udpserv.c)<br>
ADD_EXECUTABLE(cli udpcli.c)<br>
TARGET_LINK_LIBRARIES(cli ${APUE_LIB})<br><br>Also, consider using lowercase command names for new CMake code.  It works the same and is a lot easier on the eyes:<br><br>
cmake_minimum_required(VERSION 2.6)<br>

project(UDPCS)<br>

find_library(APUE_LIB apue)<br>

add_executable(serv udpserv.c)<br>

add_executable(cli udpcli.c)<br>

target_link_libraries(cli ${APUE_LIB})<br><br></div></div>-- <br>Philip Lowman<br>