Treating as Server code:
I have created an shared library,which contains nanomsg package functionality.
Adding DEPENDS += "nanomsg" in bb file. (Without this <nanomsg/*.h> gives "no such file are directory" errors).
Server will send some data to client via shared library(using nanomsg IPC).
Treating as Stand alone application code:
Application code calls the shared lib functionality, such that recieves data from server.
Uses target_link_libraries for the shared library and include directories.
while using bitbake
.. undefined reference 'nn_send' ... nn_socket ld: exit 1 status issues are
seen.
Please help me on this.
CMakeList.txt:
nanomsg code path in project dir:
include_directories(${XXXXX_SRC}thirdparty/nanomsg/src)
shared lib created in other project dir:
include_directories(${CMAKE_SOURCE_DIR}/xxxxx)
Test app name - nn_client:
3.
set(
COMPONENT_EXECUTABLE_NN_CLI
"nn_client"
)
Linking the shared lib with my source file
4.
target_link_libraries(${COMPONENT_EXECUTABLE_NN_CLI}
ptpnnmsg
${EXTRA_LIBS}
)
Since above one is not working added below one as an addon - where sharednnmsg located.
target_link_libraries(${COMPONENT_EXECUTABLE_NN_CLI} -L/../../../xxx/)
install(TARGETS ${COMPONENT_EXECUTABLE_NN_CLI}
DESTINATION ${CMAKE_INSTALL_BINDIR})
Instead of point-6 as above tried as
install(TARGETS nn_client
RUNTIME DESTINATION bin
)
errors while doing bitbake:
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_recv'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_freemsg'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_bind'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_shutdown'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_send'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_connect'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_socket'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_strerror'
../../../../xxxx/libptpnnmsg.so: undefined reference to `nn_errno'
Related
I am building an executable (GNUstep).
It depends on a libLibname.a static lib.
In the GNUmakefile of the executable I am linking libLibname.a like this:
executableToolName_LDFLAGS = /usr/GNUstep/Local/Library/Libraries/libLibname.a
It claims to link without errors:
Linking tool executableToolName ...
Problem: It seems to not find the symbols:
main.m:29: error: undefined reference to '._OBJC_REF_CLASS_SomeClassNameOfLibLibname'
..._LDFLAGSis only for libray targets.
For tool targets, linked libs must be listed in ADDITIONAL_OBJC_LIBS, prefixed with -l
This question already has answers here:
SFML: undefined reference to _imp_ [closed]
(2 answers)
Closed 2 years ago.
I'm trying to build a CMake project on Windows/MinGW and link it to SFML 2.5.1. CMake seems to find the libraries, and the program compiles fine, but I'm getting 'undefined reference' linker errors. I followed the SFML 2.5 CMake build instructions. What am I missing?
Errors:
[ 50%] Linking CXX executable pressure.exe
CMakeFiles\pressure.dir/objects.a(main.cpp.obj): In function `main':
C:/code/cpp/small/pressure/main.cpp:19: undefined reference to `_imp___ZN2sf6StringC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6locale'
C:/code/cpp/small/pressure/main.cpp:19: undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:/code/cpp/small/pressure/main.cpp:19: undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:/code/cpp/small/pressure/main.cpp:21: undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
C:/code/cpp/small/pressure/main.cpp:24: undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:/code/cpp/small/pressure/main.cpp:26: undefined reference to `_imp___ZN2sf6Window5closeEv'
C:/code/cpp/small/pressure/main.cpp:30: undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
C:/code/cpp/small/pressure/main.cpp:30: undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:/code/cpp/small/pressure/main.cpp:32: undefined reference to `_imp___ZN2sf6Window7displayEv'
C:/code/cpp/small/pressure/main.cpp:19: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
C:/code/cpp/small/pressure/main.cpp:19: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
collect2.exe: error: ld returned 1 exit status
My project's CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(pressure)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
if(WIN32)
#set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR C:/lib/cpp/SFML-2.5.1/lib/cmake/SFML)
endif()
set(SFML_LIBRARIES sfml-graphics sfml-audio)
set(pressure_VERSION_MAJOR 0)
set(pressure_VERSION_MINOR 1)
configure_file(
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
include_directories("${PROJECT_BINARY_DIR}")
set(EXECUTABLE_NAME "pressure")
find_package(SFML 2.5 COMPONENTS system window graphics audio main network REQUIRED)
add_executable(pressure main.cpp)
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
This error has been mentioned a few times on the Stack Overflow site:
SFML: undefined reference to _imp_
Cannot compile SFML project using cmake
CMake+SFML Linker error, even though library is specified in CMakeLists.txt
More often than not, this specific linker error appears to occur when there are incompatibilities between the SFML libraries and what they are linked to. From the SFML 2.5.1 downloads page, there are several versions of the SFML pre-built libraries available. Make sure you download and reference the version that matches your compiler (e.g. MinGW, Visual C++ 12, Visual C++ 15, etc.).
On Windows, several different compilers are supported; so for example, if you are building your project with Visual Studio 15, be sure you've downloaded and referenced the Visual C++ 15 SFML libraries. Also be sure the SFML libraries match the architecture of your compiler (i.e. 32-bit or 64-bit).
If you don't see the compiler you're using in the list offered on the SFML downloads page, you can download the SFML source and build it yourself using your compiler. This will help ensure the SFML libraries have binary compatibility with your project. Or, you can browse through older versions of SFML pre-built libraries to see if any of those match the compiler you're using for your project.
After sucessfully building libuv on windows in a mingw64 environment, I'm having a problems linking the libuv.dll/libuv.lib that are built as part of the vsbuild.bat build script.
When I build libuv by myself from the sources to produce either a .dll or .lib I can link without any issues.
The errors I get back when including the static or shared lib from the vsbuild.bat are related to undefined references e.g.:
[ 9%] Linking CXX shared library ..\buildcmake\bin\libuws.dll
CMakeFiles\uws.dir/objects.a(Group.cpp.obj): In function `uS::Async::start(void (*)(uS::Async*))':
D:/test/uWebSockets/git/src/Libuv.h:37: undefined reference to `uv_async_init'
CMakeFiles\uws.dir/objects.a(Group.cpp.obj): In function `uS::Async::close()':
D:/test/uWebSockets/git/src/Libuv.h:45: undefined reference to `uv_close'
...etc
The specific part of my cmake script that deals with the linking is:
find_library(LIBUV_STATIC_LIBRARY NAMES libuv.lib PATHS ${LIBUV_DEPS_DIR}/git/Debug ${LIBUV_DEPS_DIR}/git/Release PATH_SUFFIXES ${CMAKE_BUILD_TYPE}/lib NO_DEFAULT_PATH)
find_library(LIBUV_SHARED_LIBRARY NAMES libuv.dll PATHS ${LIBUV_DEPS_DIR}/git PATH_SUFFIXES .libs ${CMAKE_BUILD_TYPE} NO_DEFAULT_PATH)
MESSAGE(STATUS ".${LIBUV_STATIC_LIBRARY}")
MESSAGE(STATUS ".${LIBUV_SHARED_LIBRARY}")
include_directories(${UWS_DIR} ${LIBUVDIR_SRC} ${ZLIB_DIR_INCLUDE} ${LIBUVDIR_INCLUDE} ${OPENSSL_INCLUDE_DIR} )
add_library(uws SHARED ${UWS_SOURCES})
target_link_libraries(uws PUBLIC ${LIBUV_SHARED_LIBRARY} ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
add_definitions(-D_WIN32_WINNT=0x0A00)
cmake output shows the libraries are found ok...
-- .D:/test/deps/libuv/git/Debug/lib/libuv.lib
-- .D:/test/deps/libuv/git/Debug/libuv.dll
Version of CMake is 3.9.something and I'm using nu-mingw with g++.
There is a project, when building the project has problem with a linking library to the project.
I would be very grateful if someone told me how to solve this problem.
As I understand the problem is in the correct location of the library. So that when build the project correctly linked with it.
This is projects file CmakeList
cmake_minimum_required(VERSION 3.5.1)
project(maintenance)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC OFF)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_VERBOSE_MAKEFILE ON)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Charts REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Network REQUIRED)
include_directories(../../088)
#include(FindPackageHandleStandardArgs)
#find_library(Network_LIBRARY NAMES NetworkCommunication PATHS ../../088/build-libs-ubuntu-Release)
#find_package_handle_standard_args(Network DEFAULT_MSG Network_LIBRARY)
add_library(NetworkCommunication SHARED IMPORTED)
set_property(TARGET NetworkCommunication PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/../../088/build-libs-ubuntu-Release/libNetworkCommunication.so)
set(Network_LIBRARY NetworkCommunication)
#link_directories(${CMAKE_CURRENT_LIST_DIR}/../../088/build-libs-ubuntu-Release)
qt5_add_resources(RCC_RESOURCES resources.qrc)
file(GLOB SOURCE_FILES_2
${CMAKE_CURRENT_SOURCE_DIR}/cop/*.h
${CMAKE_CURRENT_SOURCE_DIR}/cop/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/curves/*.h
${CMAKE_CURRENT_SOURCE_DIR}/curves/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/curves/shapes/*.h
${CMAKE_CURRENT_SOURCE_DIR}/curves/shapes/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/general/*.h
${CMAKE_CURRENT_SOURCE_DIR}/general/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/load_cells/*.h
${CMAKE_CURRENT_SOURCE_DIR}/load_cells/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/motors/*.h
${CMAKE_CURRENT_SOURCE_DIR}/motors/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/passive_mode/*.h
${CMAKE_CURRENT_SOURCE_DIR}/passive_mode/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/settings/*.h
${CMAKE_CURRENT_SOURCE_DIR}/settings/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/system/*.h
${CMAKE_CURRENT_SOURCE_DIR}/system/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../Gener095/Messages/*.h
${CMAKE_CURRENT_SOURCE_DIR}/../Gener095/Messages/*.cpp
)
set(SOURCE_FILES
Error.cpp
Error.hpp
main.cpp
MainWindow.cpp
MainWindow.h
NetworkCommunicator.cpp
NetworkCommunicator.h
Utils.cpp
Utils.h
ITab.h
)
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${SOURCE_FILES_2} ${RCC_RESOURCES})
#target_link_libraries(${PROJECT_NAME} ${Network_LIBRARY})
target_link_libraries(${PROJECT_NAME} NetworkCommunication)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Charts Qt5::Xml Qt5::Network)
include(../../088/BuildUtilities/scripts/lib_setup.cmake)
and logs with errors
...
[ 95%] Building CXX object CMakeFiles/maintenance.dir/qrc_resources.cpp.o
[ 97%] Building CXX object CMakeFiles/maintenance.dir/maintenance_autogen/moc_compilation.cpp.o
[100%] Linking CXX executable maintenance
CMakeFiles/maintenance.dir/MainWindow.cpp.o: In function `MainWindow::MainWindow(QMainWindow*)':
/media/blinct/free1/QtProjects/Applications/095/maintenance/MainWindow.cpp:74: undefined reference to `TenzGraphTab::TenzGraphTab(QWidget*)'
CMakeFiles/maintenance.dir/maintenance_autogen/moc_compilation.cpp.o: In function `AngleSensors::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)':
/media/blinct/free1/QtProjects/Applications/095/maintenance/cmake-build-debug/maintenance_autogen/ECUKZBRF6L/moc_AngleSensors.cpp:92: undefined reference to `AngleSensors::OnSetNullPosition()'
/media/blinct/free1/QtProjects/Applications/095/maintenance/cmake-build-debug/maintenance_autogen/ECUKZBRF6L/moc_AngleSensors.cpp:93: undefined reference to `AngleSensors::OnResetAccel()'
/media/blinct/free1/QtProjects/Applications/095/maintenance/cmake-build-debug/maintenance_autogen/ECUKZBRF6L/moc_AngleSensors.cpp:94: undefined reference to `AngleSensors::OnDataReceived(QString, QMap<QString, QVariant>)'
/media/blinct/free1/QtProjects/Applications/095/maintenance/cmake-build-debug/maintenance_autogen/ECUKZBRF6L/moc_AngleSensors.cpp:95: undefined reference to `AngleSensors::OnHandleUp()'
/media/blinct/free1/QtProjects/Applications/095/maintenance/cmake-build-debug/maintenance_autogen/ECUKZBRF6L/moc_AngleSensors.cpp:96: undefined reference to `AngleSensors::OnHandleDown()'
/media/blinct/free1/QtProjects/Applications/095/maintenance/cmake-build-debug/maintenance_autogen/ECUKZBRF6L/moc_AngleSensors.cpp:97: undefined reference to `AngleSensors::OnHandleReleased()'
/media/blinct/free1/QtProjects/Applications/095/maintenance/cmake-build-debug/maintenance_autogen/ECUKZBRF6L/moc_AngleSensors.cpp:98: undefined reference to `AngleSensors::OnHandleTimer()'
CMakeFiles/maintenance.dir/maintenance_autogen/moc_compilation.cpp.o:(.data.rel.ro._ZTV17AngleSensorColumn[_ZTV17AngleSensorColumn]+0x28): undefined reference to `AngleSensorColumn::~AngleSensorColumn()'
CMakeFiles/maintenance.dir/maintenance_autogen/moc_compilation.cpp.o:(.data.rel.ro._ZTV17AngleSensorColumn[_ZTV17AngleSensorColumn]+0x30): undefined reference to `AngleSensorColumn::~AngleSensorColumn()'
CMakeFiles/maintenance.dir/maintenance_autogen/moc_compilation.cpp.o:(.data.rel.ro._ZTV17AngleSensorColumn[_ZTV17AngleSensorColumn]+0x1c0): undefined reference to `non-virtual thunk to AngleSensorColumn::~AngleSensorColumn()'
CMakeFiles/maintenance.dir/maintenance_autogen/moc_compilation.cpp.o:(.data.rel.ro._ZTV17AngleSensorColumn[_ZTV17AngleSensorColumn]+0x1c8): undefined reference to `non-virtual thunk to AngleSensorColumn::~AngleSensorColumn()'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlSerialPortImpl::setRequestToSend(bool)'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `g_sVersion_NetworkCommunication'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlUdpSocketImpl::writeDatagram(QByteArray const&, QHostAddress const&, unsigned short)'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlTcpServerImpl::isListening() const'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlFileImpl::close()'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlTcpServerImpl::hasPendingConnections() const'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlTcpSocketImpl::connectToHost(QHostAddress const&, unsigned short)'
...
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlUdpSocketImpl::readDatagram(char*, long long, QHostAddress*, unsigned short*)'
../../../088/build-libs-ubuntu-Release/libNetworkCommunication.so: undefined reference to `BtlTcpServerImpl::close()'
collect2: error: ld returned 1 exit status
CMakeFiles/maintenance.dir/build.make:936: recipe for target 'maintenance' failed
make[3]: *** [maintenance] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/maintenance.dir/all' failed
make[2]: *** [CMakeFiles/maintenance.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/maintenance.dir/rule' failed
make[1]: *** [CMakeFiles/maintenance.dir/rule] Error 2
Makefile:118: recipe for target 'maintenance' failed
make: *** [maintenance] Error 2
Thanks in advance.
For a very long time I can not understand how to solve this problem.
If NetworkCommunication is something you've written and already have installed, then consider including a FindNetworkCommunication.cmake file with the package. That file should contain a method for finding NetworkCommunication like so:
# Sets NetworkCommunication_FOUND if found.
#
# If NetworkCommunication_FOUND is TRUE, then the following variables are also
# set:
#
# NetworkCommunication_LIBRARY - Full path to library to link
# NetworkCommunication_INCLUDE_DIR - Path to include directory
#
# $NetworkCommunicationDIR is an environment variable that would correspond to the
# ./configure --prefix=$NetworkCommunicationDIR used in building NetworkCommunication.
#
find_path(NetworkCommunication_INCLUDE_DIR NetworkCommunication.h
HINTS
ENV NetworkCommunicationDIR
PATH_SUFFIXES include/NetworkCommunication include/NetworkCommunication include
PATHS
/opt/local
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Alexey\\NetworkCommunication\\1.00.0000;InstallDir]
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_NetworkCommunication_ARCH_DIR libs/Win64)
else()
set(_NetworkCommunication_ARCH_DIR libs/Win32)
endif()
find_library(NetworkCommunication_LIBRARY
NAMES NetworkCommunication
HINTS
ENV NetworkCommunicationDIR
PATH_SUFFIXES lib64 lib libs64 libs ${_NetworkCommunication_ARCH_DIR}
PATHS
/opt/local
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Alexey\\NetworkCommunication\\1.00.0000;InstallDir]
)
unset(_NetworkCommunication_ARCH_DIR)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NetworkCommunication DEFAULT_MSG NetworkCommunication_LIBRARY NetworkCommunication_INCLUDE_DIR)
mark_as_advanced(NetworkCommunication_LIBRARY NetworkCommunication_INCLUDE_DIR)
Copy FindNetworkCommunication.cmake into the cmake installation's Modules folders (/usr/share/cmake-3.8/Modules) or copy it to a local folder and include the path to that folder in ${CMAKE_MODULES_PATH}.
Next, in your CMakeLists.txt file of your maintenance project add the following after add_executable
Find_Package(NetworkCommunication REQUIRED)
if (NetworkCommunication_FOUND)
target_include_directories(${PROJECT_NAME} ${NetworkCommunication_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${NetworkCommunication_LIBRARY})
endif (NetworkCommunication_FOUND)
This is a good solution if NetworkCommunication is an independant library which is used by maintenance but you intend to have it used by several other libraries too. If NetworkCommunication is part of the same project solution as maintenance and is really only meant to be linked to one project ever, then there are probably simpler solutions.
In maintenance.pro for Qt Creator i have this link for this library
U_LIB_DIR_PREFIX += ../../088/build-libs
U_LIBS += NetworkCommunication
There are many similar libraries for another project and I linked like
U_LIBS += NetworkCommunication \
Logging \
UnitController \
TherapyRunnersController \
GenersControllerCommon
All these libraries are build as dynamic libraries. And after this I link this libraries to projects.
Maybe there is another way how to link library to the project?
Because if you compare this option
U_LIB_DIR_PREFIX += ../../088/build-libs-ubuntu-Release
U_LIBS += NetworkCommunication
from QtCreator project file maintenance.pro and and writing a module for each library, it turns out very strange and difficult in comparison with 2 lines from *.pro
I'm getting this error
Undefined symbols:
".objc_class_name_MyClass", referenced from:
literal-pointer#__OBJC#__cls_refs#MyClass in infoViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
When referencing the static method below:
[MyClass ClickComment:self.navigationController];
MyClass is defined in a static library that I'm referencing in my app project. When I start typing "[MyClass "..., I get message hints. The app project knows MyClass exist and which methods are defined on it. Yet, I get the above error. Commenting out this call allows the project to build without error.
In the static library, I have a .h file that references all of the library's .h files. This way, the app project needs to reference only one .h file from the static library. The static library project also has an app. I use it to test the static library. I can do the above call fine. I usually see these types of errors when the static library has build a device/debug version and the app project has build simulator/debug. However, both builds are in sync.
I know there is a reference issue but I'm unsure how to resolve it. Any suggestions?
That means that the header files are found during compilation, but the linker is not aware of the static library. Make sure your static library is listed under "Targets -> YourMainTarget > Link Binary with Libraries" in the project view.
See http://developer.apple.com/tools/XCode/XCodeprojects.html