[CMake] LINK_DIRECTORIES question...
Lars Pechan
lars.pechan at parkerpechan.com
Thu Mar 31 01:45:22 EST 2005
Hello,
I'm using CMakeCVS Win32 from the 28/3/5 and I'm having problems
linking. I have a project that I'm trying to get to build cleanly both
from nmake makefiles and VS.NET2003. I'm doing out-of-source builds.
Currently, the nmake files work fine and will consistently produce a
clean build. When I configure for VS.NET using the very same source
tree I get link errors on libs that link fine when using the makefiles.
The structure I have is roughly a top-level directory with a
CMakeLists.txt containing setup stuff. It ends with a bunch of subdirs.
I then have an exe-directory where I cobble the executable together
using a bunch of static libs generated in other directories under
top-level.
I can see in VS.NET that the linker directories are correctly setup
without me having explicitly stated the directories using
LINK_DIRECTORIES. For example (this is just an example, not a
reproducible test):
top-level (CML1.txt)
/ \ \
/ \ \
foo (CML2.txt) bar (CML3.txt) exe (CML4.txt
CML1.txt: PROJECT(top-level)
SUBDIRS(foo bar exe)
CML2.txt: SET(fooSources foo1.cpp foo2.cpp)
ADD_LIBRARY(foo ${fooSources})
CML3.txt: SET(barSources bar1.cpp bar2.cpp)
ADD_LIBRARY(bar ${barSources})
CML4.txt: ADD_EXECUTABLE(bling main.cpp)
TARGET_LINK_LIBRARIES(bling foo)
TARGET_LINK_LIBRARIES(bling bar)
The main difference with my real setup is that I have about 25
directories on the same level as foo; most of which produce a static
lib.
In VS.NET I get a 'library not found: foo.lib' whilst in the nmake
config it builds fine.
So I try to fix this by
1) Adding LINK_DIRECTORIES(${TOP-LEVEL_BINARY_DIR}/foo
${TOP-LEVEL_BINARY_DIR}/bar) to CML4.txt.
I do this despite being able to see that VS.NET already has the path
setup correctly.
Result: nmake ok, VS.NET link error (same)
Aha, VS.NET uses 'Release' and 'Debug' directories, let's add:
2) LINK_DIRECTORIES(${TOP-LEVEL_BINARY_DIR}/foo/${CMAKE_CFG_INTDIR}
${TOP-LEVEL_BINARY_DIR}/bar/${CMAKE_CFG_INTDIR}
)
Again, VS.NET already lists this path as well but I'm adding it anyway
Result: nmake ok, VS.NET sometimes gives a 'library not found: foo.lib'
but it seems it is sometimes able to find foo and then barfs on bar
instead?
What am I doing wrong? What is the best-practice for writing
CMakeLists.txt files that work for both Nmake Makefiles and VS.NET2003?
Thanks,
/Lars
More information about the CMake
mailing list