[CMake] link against a library under windows
Tyler Roscoe
tyler at cryptio.net
Mon Jan 31 12:10:27 EST 2011
On Mon, Jan 31, 2011 at 08:12:49AM +0100, ycollette.nospam at free.fr wrote:
> if (MKL_FOUND)
> set(LINK_PATHS ${LINK_PATHS} "${mkl_solver_PATH}")
> endif (MKL_FOUND)
> if (MPI_FOUND)
> set(LINK_PATHS ${LINK_PATHS} "${MPI_BASE_PATH}/lib")
> endif (MPI_FOUND)
>
> link_directories(${LINK_PATHS})
Don't use link_directories(). Instead pass the full path to
target_link_libraries().
> set(LINK_LIBS odbc32 libifport libifcore)
>
> if (MKL_FOUND)
> set(LINK_LIBS ${LINK_LIBS} ${ATLAS_LIBRARIES})
> endif (MKL_FOUND)
>
> if (MPI_FOUND)
> set(LINK_LIBS ${LINK_LIBS} fmpich2)
> endif (MPI_FOUND)
>
> target_link_libraries(arc2d ${LINK_LIBS})
>
> Now, if I build my project, there is a link error because a lot of
> symbols are not found. If I do a nmake VERBOSE=1, I see that the link
> command has only the last library: fmpich2.
You may also be interested in list(... APPEND ...). Maybe you need
quotes to insure that LINK_LIBS is set correctly the way you're doing
it?
> So, my question is: how do I add several libraries in the command
> "target_link_libraries" and how do I add several paths in
> link_directories under windows ?
Your approach is fine. I would inspect the value of LINK_LIBS that is
passed to target_link_libraries() to make sure it's what you expect it
to be.
> Do I need to add a ".lib" string to each libraries ?
No.
> Do I need to add the complete path to each libraries ?
No, but it is highly recommended.
hth,
tyler
More information about the CMake
mailing list