On 12/21/2010 04:13 PM, Pere Mato Vila wrote: > Dear all, > > I am trying to build shared libraries on Windows exporting all symbols. > This is as an alternative of instrumenting the code with dllimport/dllexport > declarations. For this I do build first a static library from which I get all > the defined symbols to write a .DEF file which is then used to build the > shared library. The CMake code (using version 2.8.3) looks like this: > > add_library( ${library}-static STATIC ${sources} ) > add_custom_command( OUTPUT {library}.def COMMAND <using ${library}-static> > DEPENDS ${library}-static ) > add_library(${library} SHARED ${library}.def) > target_link_libraries(${library} ${library}-static ${other-libs} ) > set_target_properties(${library} PROPERTIES LINK_INTERFACE_LIBRARIES > ${other-libs}) > > This works just fine when using the nmake generator. The library is > created and has all the symbols are exported as desired. But, when using > Visual C++ 2008 express edition I get the following error message: > > 1>.\mylib.dir\Debug\mylib.dll.intermediate.manifest : general error c1010070: > Failed to load and parse the manifest. The system cannot find the file > specified. > > The problem is that the shared library has been defined without any 'real' > source file (only the .def file is declared) and somehow the generated code > does not produce the required manifest file. Does anybody see a problem with > these kind of constructs? Should it just work from within the IDE? > Experimentally I have found a workaround, which consists in adding a dummy > source file in the shared library definition. > > ... > file( WRITE ${library}.cpp "// empty file!!!\n" ) > add_library( ${library} SHARED ${library}.cpp ${library}.def) > ... > > > I have also noticed that the dependency of the shared library to the .def > file is also missing. This is, newer versions of the .def file does not > trigger a re-build of the shared library.
AFAIK, this is because CMake does not know how to handle a .def file for incorporation in the target, i.e. ${library}.def has no LANGUAGE property. Thus, its inclusion in the target's sources results in the execution of the custom command only. Perhaps, you can enhance your workaround with the dummy ${library}.cpp as follows: ADD_CUSTOM_COMMAND( OUTPUT {library}.def COMMAND <using ${library}-static> COMMAND ${CMAKE_COMMAND} -E touch ${library}.cpp DEPENDS ${library}-static ) This would invalidate ${library}.cpp each time ${library}.def is regenerated, so the dummy is recompiled and ${library} relinked. Regards, Michael PS: Don't write to the source directory with FILE(WRITE ...) or the like. _______________________________________________ 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