CMake: Reference external library from static library - c++

I've C++ project build using CMake and currently facing 1 issue, brief description below
lib_common -- STATIC library
lib common uses libconfig to load common configurations used in other project.
script_executor -- CMake project
It references above static library and also add external library libconfig, see below:
add_executable(script_executor)
target_link_libraries(script_executor "-lconfig++" "-llibcommon")
So I'm referencing llibcommon inside this project and llibcommon also uses libconfig which is already reference("-lconfig++") from this project.
But I'm still getting undefined reference to libconfig::Config::Config()
Environment details:
UBuntu 16.04,
cmake version 3.5.1,
gcc version 5.4.0,
g++ version 5.4.0

Related

Compiling assimp from source does not generate libassimp file

So I compiled the assimp library with cmake using the x64_x86 developer command prompt that was said to be required. (When I tried using the regular console cmake did an error that it could not find 'the cl compiler').
After some time it finally compiled without errors with the following commands:
cmake CMakeLists.txt -DASSIMP_BUILD_ASSIMP_TOOLS=OFF
cmake --build .
It built 3 files:
C static library zlibstaticd.lib
CXX shared library ..\bin\assimp-vc142-mtd.dll
CXX executable ..\bin\unit.exe
But there was no libassimp.a or libassimp.so that I can link against in MinGW. I tried just linking with te dll in my own project with:
-L\"{assimp root directory}/bin\"
-lassimp-vc142-mtd
and it failed with "undefined reference to `Assimp::Importer::Importer()"
How can i get the lib file to link against?
I installed MSYS2, replaced my existing MinGW installation with MSYS, libraries installed flawlessly and everything works now.
My mistake was that:
I was compiling the library with VS C++ toolkit while I'm compiling my project with MInGW make and g++
even after I compiled assimp the correct way, version 5.2.4 couldn't find some header, 5.2.3 and some older versions compiled successfully, but failed some unit tests (God knows why). Seemed to always hit some unresolved issue on GitHub. Never again compiling libraries from source.

How to build MLPack library as a static library using NDK-build?

Can I build a library like mlpack which has only .hpp file as a shared library using NDK-Build?
I am trying to build an API using ndk-build from linux for android arm64 and armeabi-v7a. But my API has a dependency on mlpack. But I can't use the libmlpack.so that I have built in my development environment as it was built in my desktop linux environment.
ld: error: ~/jni/lib/libmlpack.so is incompatible with aarch64linux
So, I was wondering if I could build the libmlpack.so for arm64 by using the library's source files. The following is the git repo for mlpack:
https://github.com/mlpack/mlpack
I was able to build boost library for android using the following git repo which seems to work fine.
https://github.com/moritz-wundke/Boost-for-Android

Custom build cmake using standard library also for project with lower gcc version

I have a custom build cmake v3.10.0 which was compiled with a gcc_4.8.3. I am using this custom build cmake to compile a cmake project that must use gcc _4.1.2 because of legacy code.
Executing cmake promted me with an error because it needs to use the libstdc++-IFX.so.6 provided by gcc_4.8.3 which I fixed by adding the path to the correct library in my LD_LIBRARY_PATH before the path to the libraries provided by gcc_4.1.2.
Compiling my project and linking an executable (which is done by c++) results in the linker taking the gcc_4.8.3 stdlibs over the gcc_4.1.2 libs. Is there any way to tell cmake to not use the libraries it needs for himself for my cmake project preferably without touching LD_LIBRARY_PATH?
Edits:
#squareskittles comment: I did read and try everything this post suggest but without any changes. The libstdc++-IFX.so.6 is still taken from gcc_4.8.3

cmake: How to link subdirectory library by ignoring sysroot library?

I am trying to cross compile an application for a different platform (quark processor) using cmake. The platform has provided an SDK to me. My application requires a newer version of one of the libraries in the SDK. I have added the new source code for the library using add_subdirectory(). But my problem is when I use target_link_libraries(), cmake is linking the older version of the library in my SDK. How to enable cmake ignore the library version in the SDK sysroot, and only use the new library version present in the subdirectory?
Edit: My apologies for the initial lack of details.Adding more details to the question as suggested.
My CMakeLists.txt include the following statements
add_subdirectory(libs/mosquitto-1.4.10)
target_link_libraries(myapp mosquittopp)
As mentioned, my problem is that the SDK I am using contains a 1.4 version of mosquitto library. The target_link_libraries() only links the 1.4 version and not the newer 1.4.10 version, even though cmake successfully builds the 1.4.10 version.

target platform supports only STATIC libraries not shared library issue

I am trying to compile c++ project on Redhat Linux 4.1.2 machine using Cmake utility.
In CMakeLists.txt i have specfied GenericUSMModules as follows.
ADD_LIBRARY(
GenericUSMModules SHARED
../../Generic/GenericUSMModules/GMUSMActState.cpp
../../Generic/GenericUSMModules/GMUSMActState.h
../../Generic/GenericUSMModules/GMUSMAdditionalOfferChecksAndEdits.cpp
../../Generic/GenericUSMModules/GMUSMAdditionalOfferChecksAndEdits.h
../../Generic/GenericUSMModules/GMUSMAlignmentOfProductsConfigurationAndStrategicOrderManagerChecksAndEdits.cpp
../../Generic/GenericUSMModules/GMUSMAlignmentOfProductsConfigurationAndStrategicOrderManagerChecksAndEdits.h
../../Generic/GenericUSMModules/GMUSMAllSitePart2SiteChecksAndEdits.cpp
)
when i run make command to compile c++ project , i got following error.
"ADD_LIBRARY for library GenericUSMModules is used with the SHARED option,
but the target platform supports only STATIC libraries. Building it STATIC instead.
This may lead to problems."
I am not able to understand meaning of platform doesn't support share library.
because after compilation, it generate static library(GenericUSMModules.a) not share library(GenericUSMModules.so)
please help me in this regard.
After lot of search i found that issue is due to incompatible cmake on RehHat Linux Machine.
I installed latest cmake 2.8.8 on RedHat. It solved problem and now it generates share library(.so files).