У меня довольно простой вопрос о CMake, и я буду признателен за любую помощь.

ПРОБЛЕМА : Когда я пытаюсь скомпилировать gSOAP с чистым GCC, все в порядке, но когда я использую CMake для создания файла Makefile и его сборки, я получаю ошибку связи.

Вот рабочая команда gcc (но это не очень хорошее решение):

c++ -o vms_server -Wall -fpermissive -DWITH_OPENSSL -DWITH_DOM -DWITH_ZLIB \
  -I. -I gen -I libs/gsoap-2.8/gsoap/plugin -I libs/gsoap-2.8/gsoap/custom -I libs/gsoap-2.8/gsoap \
  main.cpp \
  gen/soapC.cpp \
  gen/wsddClient.cpp \
  gen/wsddServer.cpp \
  gen/soapAdvancedSecurityServiceBindingProxy.cpp \
  gen/soapDeviceBindingProxy.cpp \
  gen/soapDeviceIOBindingProxy.cpp \
  gen/soapImagingBindingProxy.cpp \
  gen/soapMediaBindingProxy.cpp \
  gen/soapPTZBindingProxy.cpp \
  gen/soapPullPointSubscriptionBindingProxy.cpp \
  gen/soapRemoteDiscoveryBindingProxy.cpp \
  libs/gsoap-2.8/gsoap/stdsoap2.cpp \
  libs/gsoap-2.8/gsoap/dom.cpp \
  libs/gsoap-2.8/gsoap/plugin/smdevp.c \
  libs/gsoap-2.8/gsoap/plugin/mecevp.c \
  libs/gsoap-2.8/gsoap/plugin/wsaapi.c \ 
  libs/gsoap-2.8/gsoap/plugin/wsseapi.c \
  libs/gsoap-2.8/gsoap/plugin/wsddapi.c \
  -lcrypto -lssl -lz

Вот проблемный файл CMakeLists.txt:

cmake_minimum_required(VERSION 3.10.2)
project(vms_server LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_definitions(-Wall -fpermissive -DWITH_OPENSSL -DWITH_DOM -DWITH_ZLIB)

find_package(OpenSSL REQUIRED)
find_package(ZLIB)

SET(SRC_FILES main.cpp)

SET(GSOAP_DEP_FILES
    libs/gsoap-2.8/gsoap/stdsoap2.cpp 
    libs/gsoap-2.8/gsoap/dom.cpp 
    libs/gsoap-2.8/gsoap/plugin/smdevp.c
    libs/gsoap-2.8/gsoap/plugin/mecevp.c
    libs/gsoap-2.8/gsoap/plugin/wsse2api.c
    libs/gsoap-2.8/gsoap/plugin/wsaapi.c 
    libs/gsoap-2.8/gsoap/plugin/wsseapi.c
    libs/gsoap-2.8/gsoap/plugin/wsddapi.c
)

SET(GEN_FILES 
    gen/soapC.cpp 
    gen/wsddClient.cpp 
    gen/wsddServer.cpp 
    gen/soapAdvancedSecurityServiceBindingProxy.cpp 
    gen/soapDeviceBindingProxy.cpp 
    gen/soapDeviceIOBindingProxy.cpp 
    gen/soapImagingBindingProxy.cpp 
    gen/soapMediaBindingProxy.cpp 
    gen/soapPTZBindingProxy.cpp 
    gen/soapPullPointSubscriptionBindingProxy.cpp 
    gen/soapRemoteDiscoveryBindingProxy.cpp 
)

include_directories( 
    libs/gsoap-2.8/gsoap/plugin
    libs/gsoap-2.8/gsoap/custom
    libs/gsoap-2.8/gsoap
    gen
)

add_executable(vms ${SRC_FILES} ${GSOAP_DEP_FILES} ${GEN_FILES})

target_link_libraries(vms OpenSSL::Crypto OpenSSL::SSL ${ZLIB_LIBRARIES})

Команда cmake . работает без предупреждений или проблем, но затем make выдает ошибку:

Scanning dependencies of target vms
[  6%] Building CXX object CMakeFiles/vms.dir/main.cpp.o
/home/guy/Desktop/vms_server-c++/main.cpp: In function ‘int main()’:
/home/guy/Desktop/vms_server-c++/main.cpp:194:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<tt__Profile*>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  194 |     for (int i = 0; i < GetProfilesResponse.Profiles.size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/guy/Desktop/vms_server-c++/main.cpp: At global scope:
/home/guy/Desktop/vms_server-c++/main.cpp:308:13: warning: ‘void dyn_destroy_function(CRYPTO_dynlock_value*, const char*, int)’ defined but not used [-Wunused-function]
  308 | static void dyn_destroy_function(struct CRYPTO_dynlock_value *l, const char *file, int line)
      |             ^~~~~~~~~~~~~~~~~~~~
/home/guy/Desktop/vms_server-c++/main.cpp:300:13: warning: ‘void dyn_lock_function(int, CRYPTO_dynlock_value*, const char*, int)’ defined but not used [-Wunused-function]
  300 | static void dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line)
      |             ^~~~~~~~~~~~~~~~~
/home/guy/Desktop/vms_server-c++/main.cpp:291:37: warning: ‘CRYPTO_dynlock_value* dyn_create_function(const char*, int)’ defined but not used [-Wunused-function]
  291 | static struct CRYPTO_dynlock_value *dyn_create_function(const char *file, int line)
      |                                     ^~~~~~~~~~~~~~~~~~~
[ 13%] Building CXX object CMakeFiles/vms.dir/libs/gsoap-2.8/gsoap/stdsoap2.cpp.o
[ 20%] Building CXX object CMakeFiles/vms.dir/libs/gsoap-2.8/gsoap/dom.cpp.o
[ 26%] Building CXX object CMakeFiles/vms.dir/gen/soapC.cpp.o
[ 33%] Building CXX object CMakeFiles/vms.dir/gen/wsddClient.cpp.o
[ 40%] Building CXX object CMakeFiles/vms.dir/gen/wsddServer.cpp.o
[ 46%] Building CXX object CMakeFiles/vms.dir/gen/soapAdvancedSecurityServiceBindingProxy.cpp.o
[ 53%] Building CXX object CMakeFiles/vms.dir/gen/soapDeviceBindingProxy.cpp.o
[ 60%] Building CXX object CMakeFiles/vms.dir/gen/soapDeviceIOBindingProxy.cpp.o
[ 66%] Building CXX object CMakeFiles/vms.dir/gen/soapImagingBindingProxy.cpp.o
[ 73%] Building CXX object CMakeFiles/vms.dir/gen/soapMediaBindingProxy.cpp.o
[ 80%] Building CXX object CMakeFiles/vms.dir/gen/soapPTZBindingProxy.cpp.o
[ 86%] Building CXX object CMakeFiles/vms.dir/gen/soapPullPointSubscriptionBindingProxy.cpp.o
[ 93%] Building CXX object CMakeFiles/vms.dir/gen/soapRemoteDiscoveryBindingProxy.cpp.o
[100%] Linking CXX executable vms
CMakeFiles/vms.dir/main.cpp.o: In function `set_credentials(soap*)':
main.cpp:(.text+0x65): undefined reference to `soap_wsse_delete_Security'
main.cpp:(.text+0x7d): undefined reference to `soap_wsse_add_Timestamp'
main.cpp:(.text+0xa2): undefined reference to `soap_wsse_add_UsernameTokenDigest'
CMakeFiles/vms.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x3ec): undefined reference to `soap_wsse'
CMakeFiles/vms.dir/gen/wsddServer.cpp.o: In function `soap_serve___wsdd__Hello(soap*)':
wsddServer.cpp:(.text+0x63c): undefined reference to `__wsdd__Hello(soap*, wsdd__HelloType*)'
CMakeFiles/vms.dir/gen/wsddServer.cpp.o: In function `soap_serve___wsdd__Bye(soap*)':
wsddServer.cpp:(.text+0x751): undefined reference to `__wsdd__Bye(soap*, wsdd__ByeType*)'
CMakeFiles/vms.dir/gen/wsddServer.cpp.o: In function `soap_serve___wsdd__Probe(soap*)':
wsddServer.cpp:(.text+0x866): undefined reference to `__wsdd__Probe(soap*, wsdd__ProbeType*)'
CMakeFiles/vms.dir/gen/wsddServer.cpp.o: In function `soap_serve___wsdd__ProbeMatches(soap*)':
wsddServer.cpp:(.text+0x97b): undefined reference to `__wsdd__ProbeMatches(soap*, wsdd__ProbeMatchesType*)'
CMakeFiles/vms.dir/gen/wsddServer.cpp.o: In function `soap_serve___wsdd__Resolve(soap*)':
wsddServer.cpp:(.text+0xa90): undefined reference to `__wsdd__Resolve(soap*, wsdd__ResolveType*)'
CMakeFiles/vms.dir/gen/wsddServer.cpp.o: In function `soap_serve___wsdd__ResolveMatches(soap*)':
wsddServer.cpp:(.text+0xba5): undefined reference to `__wsdd__ResolveMatches(soap*, wsdd__ResolveMatchesType*)'
collect2: error: ld returned 1 exit status
CMakeFiles/vms.dir/build.make:436: recipe for target 'vms' failed
make[2]: *** [vms] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/vms.dir/all' failed
make[1]: *** [CMakeFiles/vms.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
0
guy 22 Окт 2019 в 21:23

1 ответ

Лучший ответ

Я вижу, что ваши файлы .c не собираются, когда вы компилируете с использованием созданного CMake Makefile; это вызывает ошибки ссылки. Поскольку вы компилируете проект C ++ (CXX), CMake игнорирует файлы .c. Вы можете попробовать указать CMake рассматривать .c как файл C ++, добавив расширение файла c к CMAKE_LANG_SOURCE_FILE_EXTENSIONS:

list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS c)

Это радикальный шаг, и вы можете не захотеть, чтобы его применяли ко всем вашим проектам на C ++. Более точным подходом было бы установить для свойства LANGUAGE значение C ++ для каждого исходного файла .c с помощью set_source_files_properties():

# Split up the GSOAP_DEP_FILES variable based on the file extension (.c or .cpp).
SET(GSOAP_DEP_CPP_FILES
    libs/gsoap-2.8/gsoap/stdsoap2.cpp 
    libs/gsoap-2.8/gsoap/dom.cpp 
)
SET(GSOAP_DEP_C_FILES
    libs/gsoap-2.8/gsoap/plugin/smdevp.c
    libs/gsoap-2.8/gsoap/plugin/mecevp.c
    libs/gsoap-2.8/gsoap/plugin/wsaapi.c 
    libs/gsoap-2.8/gsoap/plugin/wsseapi.c
    libs/gsoap-2.8/gsoap/plugin/wsddapi.c
)

... 

# Set the language for the .c files to C++, so CMake includes them for compilation.
set_source_files_properties(${GSOAP_DEP_C_FILES} PROPERTIES LANGUAGE CXX)

add_executable(vms ${SRC_FILES} ${GSOAP_DEP_CPP_FILES} ${GSOAP_DEP_C_FILES} ${GEN_FILES})
0
squareskittles 23 Окт 2019 в 15:11