[CMake] shared libraries .lib .dll

Ingrid Kemgoum ingrid.kemgoum at gmail.com
Wed Jun 11 03:49:42 EDT 2008


hi
i've done what you told be (not to define de -D..) and i do have a .lib too
but the problem of the link with the dll still exist.
maybe it's my fault
there is my code in the three directories(i'm using visual 8 2005 and cmake
2.6)

*In the project directory :*
cmake_minimum_required(VERSION 2.6)
# The name of our project is "HELLO".  CMakeLists files in this project can
# refer to the root source directory of the project as ${HELLO_SOURCE_DIR}
and
# to the root binary directory of the project as ${HELLO_BINARY_DIR}.
project (HELLO)
set(CMAKE_USE_RELATIVE_PATH "true")
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
subdirs(Hello Demo)

*In the hello directory (containing a hello.h and hello.cpp and is a shared
library):*
cmake_minimum_required(VERSION 2.6)
# Create a library called "Hello" which includes the source file
"hello.cxx".
# The extension is already found.  Any number of sources could be listed
here.
#Project(Hello) #ajouté
#ADD_DEFINITIONS(-DHello_DLL_EXPORT) #ajuté
add_library (Hello SHARED hello.cxx)

*In demo directory:*
cmake_minimum_required(VERSION 2.6)
# Make sure the compiler can find include files from our Hello library.
include_directories (${HELLO_SOURCE_DIR}/Hello)
# Make sure the linker can find the Hello library once it is built.
link_directories (${HELLO_BINARY_DIR}/Hello)
# Add executable called "helloDemo" that is built from the source files
# "demo.cxx" and "demo_b.cxx".  The extensions are automatically found.
add_executable (helloDemo demo.cxx demo_b.cxx )

# Link the executable to the Hello library.
target_link_libraries (helloDemo Hello)
if(MSVC_VERSION)
  set_target_properties(Hello PROPERTIES
    LINK_FLAGS " /INCREMENTAL:NO /MANIFEST /NOLOGO"
 #COMPILE_FLAGS "-DHELLO_EXPORTS"  #ajouté in last a verif demin
 )
endif(MSVC_VERSION)

thanks for all

2008/6/10 Martin Apel <martin.apel at simpack.de>:

> you have probably used declspec(export) for both cases: Compiling AND using
> the DLL.
> In my example you have to compile your DLL with a define -DBase_EXPORTS,
> which causes the
> SPCK_BASE_EXPORT to resolve to declspec(export). When you USE the DLL
> somewhere, you must not define
> this item, so SPCK_BASE_EXPORT will resolve to declspec(import).
>
> Hope this helps.
>
> Martin
>
> Ingrid Kemgoum wrote:
>
>> hi,
>> i've taken your advice on the __declspec stuff and test it on a hello
>> world project. i do have a .lib now but with a warning
>> "
>> hello.cxx
>>
>> ..\..\CMakeExample\Hello\hello.cxx(5) : warning C4273: 'Hello::Print' :
>> inconsistent dll linkage
>>
>> h:\workspace\cmakeexample\cmakeexample\hello\hello.h(18) : see previous
>> definition of 'Print'
>>
>> is that normal? anyway there is a problem: the application fail to find
>> the .exe and the .dll though i fixed those paths in the CMakeLists.txt.
>>
>> what could be the problem?
>>
>> thanks for help
>>
>> Ingrid
>>
>>
>>
>>
>> 2008/6/10 Martin Apel <martin.apel at simpack.de <mailto:
>> martin.apel at simpack.de>>:
>>
>>    Ingrid Kemgoum wrote:
>>
>>        hi and sorry to disturb
>>        (i'm french and my english is not that good)
>>        but i've seen on cmake.org <http://cmake.org/>
>>        <http://cmake.org <http://cmake.org/>> that i'm having the
>>
>>        same problem as you did.
>>
>>        i'm building a c++ project and from a shared library i only
>>        have the .dll (not the .lib)
>>         i dont understand explanations on cmake so could you please
>>        give me some?
>>         thanks in advance and regards
>>         Ingrid
>>
>>    Hi Ingrid,
>>
>>    on Windows you have to tell the compiler/linker, which symbols
>>    should be exported from a DLL. There is a Microsoft extension to C++
>>    using a declspec(export) and declspec(import) prefix for DLL
>>    functions. There's another possibility to use a so-called
>>    .def-file to tell the compiler,
>>    which symbols to export. If you have not told the compiler using
>>    one of the two ways, no symbols are exported and thus no .lib file
>>    generated.
>>    Please google for the explanation of the declspec keyword, it is
>>    somewhat beyond my available time to explain it in detail. What I
>>    did looks roughly as follows:
>>
>>    #ifdef WIN32
>>    #ifdef Base_EXPORTS
>>    #define SPCK_BASE_EXPORT __declspec(dllexport)
>>    #else
>>    #define SPCK_BASE_EXPORT __declspec(dllimport)
>>    #endif
>>    #else
>>    #define SPCK_BASE_EXPORT
>>    #endif
>>
>>    class SPCK_BASE_EXPORT Transformer
>>    {
>>    ...
>>    };
>>
>>    Hope this helps,
>>
>>    Martin
>>    --
>>
>>
>
> --
>
> Martin Apel                                     Tel:     0049 8153 9288-47
> Software Architect                              E-Mail:
> martin.apel at simpack.de
>
> INTEC GmbH                                      Tel:     0049 8153 9288-0
> Argelsrieder Feld 13                            Fax:     0049 8153 9288-11
> 82234 Wessling                                  E-Mail:  intec at simpack.de
> Germany                                         URL:
> http://www.simpack.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080611/c2657ac4/attachment-0001.htm>


More information about the CMake mailing list