[CMake] xxxxxSPAMxxxxx Simple Question Regarding Link Libraries on Linux

Philip Lowman philip at yhbt.com
Tue Jan 5 20:17:23 EST 2010


Whoever developed foo.a should call it libfoo.a instead so it meets
standards.  All libraries on Linux are supposed to start with "lib"
with the possible exception of dynamically loaded shared libraries
(i.e. plugins).

If you still can't rename it, you can do target_link_libraries(bar
/full/path/to/foo.a).

To get the full path of your source tree you can use
${CMAKE_CURRENT_SOURCE_DIR}.

On Tue, Jan 5, 2010 at 5:57 PM,  <ed.jung at agileplanet.com> wrote:
> How do I link a *.a file that doesn't start with "lib" to an executable?
> For example, if I have a library named foo.a with a function called getnum,
> how do I link to foo.a in CMakeLists.txt?
>
> If my executable file is
> ---main.cpp---
> extern int getnum();
> int main(int, char**)    { cout << getnum() << endl;}
> ----------------
> and my CMakeFile is
> ---CMakeLists.txt---
> PROJECT(TESTPROJECT)
> ADD_EXECUTABLE(test main.cpp foo.a)
> -----------------------
> I'll get an error about an undefined reference to getnum when I run the
> makefile.
> If I use TARGET_LINK_LIBRARIES(test foo), I'll get an error about not begin
> able to find the library, since it's using the -l flag for the linker.  I'd
> rather not have to rename foo.a, because it will affect other existing
> software.
>
> Thanks,
> -Ed
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
Philip Lowman


More information about the CMake mailing list