Hi, I have a project with a library and amn app that link the library from different path.
The Project compiles fine if I link the library as SHARED, but when I try turn to STATIC,
I get the next report:
[100%] Linking CXX executable C:\Users\jos\Documents\GIT-Proyectos-Anfitrion\binDebugCosmos\orb2cosmos\orb2cosmos.exe
CMakeFiles\orb2cosmos.dir/objects.a(mocs_compilation.cpp.obj): In function `LogWriter::qt_metacast(char const*)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/binDebugCosmos/tmpBuild/orb2cosmos/orb2cosmos_autogen/EWIEGA46WW/moc_logwriter.cpp:132: undefined reference to `__imp__ZN7Logging11qt_metacastEPKc'
CMakeFiles\orb2cosmos.dir/objects.a(mocs_compilation.cpp.obj): In function `LogWriter::qt_metacall(QMetaObject::Call, int, void**)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/binDebugCosmos/tmpBuild/orb2cosmos/orb2cosmos_autogen/EWIEGA46WW/moc_logwriter.cpp:137: undefined reference to `__imp__ZN7Logging11qt_metacallEN11QMetaObject4CallEiPPv'
CMakeFiles\orb2cosmos.dir/objects.a(mocs_compilation.cpp.obj): In function `QMetaObject const* QMetaObject::staticMetaObject<Logging::staticMetaObject>()':
C:/Qt/5.15.2/mingw81_64/include/QtCore/qobjectdefs.h:577: undefined reference to `__imp__ZN7Logging16staticMetaObjectE'
CMakeFiles\orb2cosmos.dir/objects.a(mainwindow.cpp.obj): In function `MainWindow::updateFRTConfigToShip(QString const&, MainWindow::fileParameters const&, QString const&)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:492: undefined reference to `__imp__ZN11SHIPconfigC1ERK7QStringP7LoggingP7QObject'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:511: undefined reference to `__imp__ZN11SHIPconfig17writeGenericFieldE7QStringS0_8QVariantiiS0_S0_iS0_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:500: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:492: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
CMakeFiles\orb2cosmos.dir/objects.a(mainwindow.cpp.obj): In function `MainWindow::updateDACConfigToShip(QString const&, MainWindow::fileParameters const&, QString const&)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:528: undefined reference to `__imp__ZN11SHIPconfigC1ERK7QStringP7LoggingP7QObject'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:577: undefined reference to `__imp__ZN11SHIPconfig17writeGenericFieldE7QStringS0_8QVariantiiS0_S0_iS0_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:588: undefined reference to `__imp__ZN11SHIPconfig17writeGenericFieldE7QStringS0_8QVariantiiS0_S0_iS0_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:536: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:528: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
CMakeFiles\orb2cosmos.dir/objects.a(mainwindow.cpp.obj): In function `MainWindow::updatePATConfigToShip(QString const&, MainWindow::fileParameters const&, QString const&)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:609: undefined reference to `__imp__ZN11SHIPconfigC1ERK7QStringP7LoggingP7QObject'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:643: undefined reference to `__imp__ZN11SHIPconfig17writeGenericFieldE7QStringS0_8QVariantiiS0_S0_iS0_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:653: undefined reference to `__imp__ZN11SHIPconfig17writeGenericFieldE7QStringS0_8QVariantiiS0_S0_iS0_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:691: undefined reference to `__imp__ZN11SHIPconfig17writeGenericFieldE7QStringS0_8QVariantiiS0_S0_iS0_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:618: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:609: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
CMakeFiles\orb2cosmos.dir/objects.a(mainwindow.cpp.obj): In function `MainWindow::updateSTAR_USPConfigToShip(QString const&, QString const&)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:766: undefined reference to `__imp__ZN11SHIPconfigC1ERK7QStringP7LoggingP7QObject'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:775: undefined reference to `__imp__ZN11SHIPconfig10setUSPnameEiRK7QStringS2_'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:830: undefined reference to `__imp__ZN11SHIPconfig15setProbeTypeVarEhPKN5SHIP23NetRxPlateProbeTypeDataE'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:835: undefined reference to `__imp__ZN11SHIPconfig9setCtrVarEiPKN5SHIP17NetRxPlateCtrDataEb'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:838: undefined reference to `__imp__ZN11SHIPconfig9setIPOVarEihPKN5SHIP17NetRxPlateIPODataEb'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:766: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:766: undefined reference to `__imp__ZN11SHIPconfigD1Ev'
CMakeFiles\orb2cosmos.dir/objects.a(mainwindow.cpp.obj): In function `MainWindow::updateFrom_star_ini(MainWindow::elementParameters&, MainWindow::destinationParameters&)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:866: undefined reference to `__imp__ZN11SHIPconfig9setComVarERK7QStringRK8QVariantS2_'
CMakeFiles\orb2cosmos.dir/objects.a(mainwindow.cpp.obj): In function `MainWindow::updateFrom_usp(MainWindow::elementParameters&, MainWindow::destinationParameters&)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:899: undefined reference to `__imp__ZN11SHIPconfig9setUSPVarEiRK7QStringRK8QVariantS2_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:923: undefined reference to `__imp__ZN11SHIPconfig9setUSPVarEiRK7QStringRK8QVariantS2_i'
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/mainwindow.cpp:925: undefined reference to `__imp__ZN11SHIPconfig9setUSPVarEiRK7QStringRK8QVariantS2_i'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::LogWriter(QObject*)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:26: undefined reference to `__imp__ZN7LoggingC2ERK7QStringP7QObject'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::~LogWriter()':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:30: undefined reference to `__imp__ZN7LoggingD2Ev'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::getInstance(QObject*)':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:42: undefined reference to `__imp__ZN7Logging4openEv'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::writeLog(Logging::LOGLEVEL, QString const&, QString const&) const':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:70: undefined reference to `__imp__ZNK7Logging9isEnabledEv'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::writeLog(Logging::LOGLEVEL, QString const&, char const*) const':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:81: undefined reference to `__imp__ZNK7Logging9isEnabledEv'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::writeLog(Logging::LOGLEVEL, QString const&, char const*, QString const&) const':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:92: undefined reference to `__imp__ZNK7Logging9isEnabledEv'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::writeLog(Logging::LOGLEVEL, QString const&, char const*, QString const&, QString const&) const':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:103: undefined reference to `__imp__ZNK7Logging9isEnabledEv'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::writeLog(Logging::LOGLEVEL, QString const&, char const*, QString const&, QString const&, QString const&) const':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:114: undefined reference to `__imp__ZNK7Logging9isEnabledEv'
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj):C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:125: more undefined references to `__imp__ZNK7Logging9isEnabledEv' follow
CMakeFiles\orb2cosmos.dir/objects.a(logwriter.cpp.obj): In function `LogWriter::writeLog(Logging::LOGLEVEL, QDateTime const&, QString const&, QString const&) const':
C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/cosmos/orb2cosmos/logwriter.cpp:194: undefined reference to `__imp__ZNK7Logging9signalLogENS_8LOGLEVELE9QDateTime7QStringS2_11QStringList'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [C:\Users\jos\Documents\GIT-Proyectos-Anfitrion\binDebugCosmos\tmpBuild\orb2cosmos\CMakeFiles\orb2cosmos.dir\build.make:166: C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/binDebugCosmos/orb2cosmos/orb2cosmos.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:190: C:/Users/jos/Documents/GIT-Proyectos-Anfitrion/binDebugCosmos/tmpBuild/orb2cosmos/CMakeFiles/orb2cosmos.dir/all] Error 2
mingw32-make.exe: *** [Makefile:102: all] Error 2
Any help please?
Thanks in advance.
Here are the my files:
root::CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_PROJECT_NAME "testProject")
project(${CMAKE_PROJECT_NAME})
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_PARALLEL_LEVEL 8)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\Tools\\mingw810_64")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(BIN_PATH "binDebugCosmos")
else()
set(BIN_PATH "binCosmos")
set(CMAKE_BUILD_TYPE Release)
endif()
set(TMP_BUILD "tmpBuild")
set(COSMOS_LIB "cosmoslib")
set(ORB2COSMOS "orb2cosmos")
set(OUT_PATH ${CMAKE_SOURCE_DIR}/../${BIN_PATH})
set(BUILD_TEMP_PATH ${OUT_PATH}/${TMP_BUILD})
add_subdirectory(${COSMOS_LIB} ${BUILD_TEMP_PATH}/${COSMOS_LIB})
include_directories(${COSMOS_LIB})
add_subdirectory(${ORB2COSMOS} "${BUILD_TEMP_PATH}/${ORB2COSMOS}")
include_directories(${ORB2COSMOS})
cosmoslib::CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUT_PATH}/${COSMOS_LIB})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUT_PATH}/${COSMOS_LIB})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUT_PATH}/${COSMOS_LIB})
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
include_directories(
../shared
../shared/ship
../shared/plc
../shared/orb
../shared/tools
)
add_library(${COSMOS_LIB} #SHARED
../shared/tools/nocpptools.h
../shared/LogarithmTable_i.h
../shared/plc.h
../shared/orb.h
cosmoslib.h
../shared/baseobject.h
../shared/cosmosdefines.h
../shared/cosmosprotocol.h
../shared/cosmosthread.h
../shared/cosmostypedef.h
../shared/configbase.h
../shared/configserver.h
../shared/configclient.h
../shared/debugout.h
../shared/ship/Typedef.h
../shared/ship/ptvvardef.h
../shared/ship/ctrvardef.h
../shared/ship/netstruct.h
../shared/ship/ipovardef.h
../shared/ship/Typedef.h
../shared/ship/fpgadef.h
../shared/shipsettings.h
../shared/shipset.h
../shared/ipaddr.h
../shared/logging.h
../shared/plc/plc.h
../shared/settingsxml.h
../shared/tcpcomm.h
../shared/utils.h
../shared/version.h
../shared/orb/A_Typedef.h
../shared/orb/C_Typedef.h
../shared/orb/EVA_defines.h
../shared/orb/G_Defines.h
../shared/orb/G_Typedef.h
../shared/orb/Header_PCD.h
../shared/orb/Typedef.h
../shared/orb/STAR.h
../shared/orbctr.h
../shared/shipparameters.h
../shared/shipconfig.h
../shared/ship.h
../shared/scaleconverter.h
../shared/tools/nocpptools.cpp
../shared/tools/ostools.cpp
baseobject.cpp
cosmoslib.cpp
cosmosprotocol.cpp
cosmosthread.cpp
configbase.cpp
configclient.cpp
configserver.cpp
shipconfig.cpp
shipparameters.cpp
shipset.cpp
shipsettings.cpp
ipaddr.cpp
logging.cpp
scaleconverter.c
settingsxml.cpp
tcpcomm.cpp
utils.cpp
orbctr.cpp
)
target_include_directories(${COSMOS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" )
if("Windows" STREQUAL "${CMAKE_SYSTEM_NAME}")
target_link_libraries(${COSMOS_LIB} PUBLIC Qt5::Core Qt5::Network iphlpapi Ws2_32 Shlwapi)
elseif("Linux" STREQUAL "${CMAKE_SYSTEM_NAME}")
target_link_libraries(${COSMOS_LIB} PUBLIC Qt5::Core Qt5::Network)
endif()
message(STATUS "___________________________________________________${COSMOS_LIB}")
target_compile_definitions(${COSMOS_LIB} PRIVATE
QT_DEPRECATED_WARNINGS=1
MAKE_COSMOS_LIB=1
COSMOS=1
COSMOSEMU=1
DEU_PACK=1
COSMOS_PACK=1
ADDITIONAL_TYPES=1
USE_GLOBAL_REGISTER_VARIABLES=0
NOCRYPT=1
NOUNCRYPT=1
UNICODE=1 #Windows
)
orb2cosmos::CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUT_PATH}/${ORB2COSMOS}) #/${ORB2COSMOS}
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(Qt5Xml REQUIRED)
include_directories(
../shared
../shared/ship
../shared/plc
../shared/orb
../shared/tools
)
link_directories(${OUT_PATH}/${COSMOS_LIB} ) #binaries
set(SOURCES
main.cpp
mainwindow.h
mainwindow.cpp
doxygen.h
logwriter.h
logwriter.cpp
)
set(UI_SOURCES
mainwindow.ui
)
qt5_wrap_ui(UI_GENERATED_HEADERS ${UI_SOURCES} )
#target_link_directories(${ORB2COSMOS} "${CMAKE_SOURCE_DIR}/../${binPath}/${COSMOS_LIB}")
add_executable(${ORB2COSMOS} ${SOURCES} ${UI_GENERATED_HEADERS})
add_dependencies(${ORB2COSMOS} ${COSMOS_LIB})
target_link_libraries(${ORB2COSMOS} PUBLIC ${COSMOS_LIB} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network Qt5::Concurrent Qt5::Xml )
target_compile_definitions(${ORB2COSMOS} PUBLIC
QT_DEPRECATED_WARNINGS=1
ORB2COSMOS=1
COSMOSEMU=1
DEU_PACK=1
COSMOS_PACK=1
ADDITIONAL_TYPES=1
USE_GLOBAL_REGISTER_VARIABLES=0
NOCRYPT=1
NOUNCRYPT=1
)