I'm trying to add .lib file and .a (x64) file to Android project with a native component but I got an error in CMakelists.txt
error:
CMake Error: Cannot determine link language for target "LIB".
CMake Error: CMake can not determine linker language for target: LIB
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
my following CMakelists like:
cmake_minimum_required(VERSION 3.20)
project(testGu)
set(CMAKE_CXX_STANDARD 14)
include_directories(GuruX)
link_directories(GuruX/include)
add_library(guruxLib STATIC IMPORTED )
add_executable(testGu main.cpp)
set_target_properties(libGuruX PROPERTIES IMPORTED_LOCATION D:\\testGu\\GuruX\\lib\\libGuruX.a)
add_library(LIB GuruX/lib/GuruxDLMS)
target_link_libraries(LIB SHARED GuruX/lib/GuruxDLMS)
where
|-GuruX
|-lib
|-libGuruX.a
|-GuruxDLMS.lib
|-includes (*.h files)
Related
I have same problem like:
How to link opencv and other dll files to output exe of visual studio 2013
the answer say:
There you change the extension of all the openCV libraries from .dll to .lib
i download the .lib in https://opencv.org/releases/, which have .lib in opencv\build\x64\vc15\lib
follow is my CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
set(prjName opencv_demo)
project(${prjName})
set(CMAKE_CXX_STANDARD 14)
# this is static libraries, have *.lib
set(OpenCV_DIR "C:\\opencv\\build\\x64\\vc15\\lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
find_package(OpenCV REQUIRED)
add_executable(opencv_demo main.cpp)
target_link_libraries(${prjName} PUBLIC ${OpenCV_LIBS})
but it still need dll.
i search that may cmake mt like
set_property(TARGET ${prjName} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
but it still need dll.
what should i do?
In my test project I have a folder structure of the following
-Root/
-Lib_so/ //folder where it contains all of the .so file
-Lib_a/ //folder where it contains all of the .a file
-Lib_dll/ //folder where it contains all of the dll file
-Includes/ //folder where it contains all of the header files
-main.cpp
I want to write a CMakeLists.txt that generates a single executable that:
automatically link ALL of the .so , .a, and/or dll files just by the folder path shown above.
link installed binaries (such as the GLFW installed by brew on mac)
I have tried the following
cmake_minimum_required(VERSION 3.0)
project(FirstOpenGL)
set(SOURCE main.cpp)
add_executable(myapp ${SOURCE})
#Below Im trying to link ALL of the libs under the "project's local path"
include_directories(${CMAKE_SOURCE_DIR}/Includes)
link_directories(LinkPathSo ${CMAKE_SOURCE_DIR}/Lib_so)
link_directories(LinkPathA ${CMAKE_SOURCE_DIR}/Lib_a)
link_directories(LinkPathDll ${CMAKE_SOURCE_DIR}/Lib_dll)
target_link_libraries(myapp LinkPathSo)
target_link_libraries(myapp LinkPathA)
target_link_libraries(myapp LinkPathDll)
# Below: Im trying to link the installed binaries on mac
find_package(glfw3 3.2 REQUIRED)
find_package(OpenGL REQUIRED)
target_include_directories(myapp ${OPENGL_INCLUDE_DIR})
target_link_libraries(myapp ${OPENGL_gl_LIBRARY})
target_link_libraries(myapp ${OPENGL_glu_LIBRARY})
Thank you all in advance
I am somewhat new to cmake and completely new to glew, glfw, and the like. I'm following a youtube channel to learn more about game engines and programming.
My problem is linking the static glew library in my project using cmake.
First, I start with the glew source code from http://mcs.une.edu.au/doc/glew-devel/index.html.
I compile it by:
cd build; cmake ./cmake; make glew_s
This adds a lib directory into the build directory with libGLEW.a
A shortened version of my CMakeLists.txt looks like:
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
project (TestProject CXX)
set(CMAKE_CXX_FLAGS "-std=c++11")
###########################
# GLEW
###########################
add_subdirectory(${CMAKE_SOURCE_DIR}/Dependencies/GLEW)
target_link_libraries(${PROJECT_NAME} glew)
and in Dependencies/GLEW I have another CMakeLists.txt:
# Add glew source and header files
file(GLOB_RECURSE glew-lib ${CMAKE_CURRENT_SOURCE_DIR}/lib/*)
file(GLOB_RECURSE glew-headers ${CMAKE_CURRENT_SOURCE_DIR}/include/GL/*)
add_library(glew ${glew-lib} ${glew-headers})
target_include_directories(glew PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/GL")
I put a copy of the libGLEW.a file into the lib directory and the include directory is copied from the glew source code include directory. It holds the GL directory, which contains the header files glew.h, wglew.h, eglew.h, and glxew.h.
When I run cmake I get the error:
CMake Error: Cannot determine link language for target "glew".
CMake Error: CMake can not determine linker language for target: glew
The glew source code also has a src directory with glew.c in it, but if I put it in the libs directory and include it in the Dependencies/GLEW/CMakeLists.txt like:
# Add glew source and header files
file(GLOB_RECURSE glew-lib ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.c)
file(GLOB_RECURSE glew-headers ${CMAKE_CURRENT_SOURCE_DIR}/include/GL/*)
add_library(glew ${glew-lib} ${glew-headers})
target_include_directories(glew PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
I get the error:
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is: CMAKE_C_COMPILE_OBJECT
CMake Error: Error required internal CMake variable not set, cmake may
be not be built correctly.
Missing variable is: CMAKE_C_CREATE_STATIC_LIBRARY
Lastly, I have tried just including the glew.c and headers in the root CMakeLists.txt like:
#########################
# GLEW
#########################
include_directories("${CMAKE_SOURCE_DIR}/Dependencies/GLEW/lib/")
include_directories("${CMAKE_SOURCE_DIR}/Dependencies/GLEW/include/GL/")
Here cmake will finish, but it won't be able to compile, saying classes do not name a type and/or are not declared in this scope.
Any help would be appreciated. I was under the impression that the libGLEW.a was the static library, and all I would have to do is link and compile it along with the headers, but that did not work.
First of all, I forgot to use
make install
after using make the first time, so I was using the incorrect libGLEW.a file.
After including the proper libGLEW.a file, my directory structure had
./Dependencies/GLEW/include/GL/*.h //header files
./Dependencies/GLEW/lib/libGLEW.a //source file
Finally, the TopLevel CMakeLists.txt is changed to include:
add_library(glew STATIC IMPORTED GLOBAL)
set_target_properties(glew PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/Dependencies/GLEW/lib/libGLEW.a )
set_target_properties(glew PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/Dependencies/GLEW/include )
If I want to include the library from a lower CMakeLists.txt such as /Dependencies/GLEW/CMakeLists.txt Then I would have to first export the library from there and then import it at the topLevel CMakeLists.txt file.
Now, in order to use glew headers in my project I can just use #include .
I am trying to use mFast for FastFix protocol on my windows machine but not able to install using cmake-gui.exe I am using Visual studio 2010 on Windows Server 2003.
cmake-gui tool.exe image with configurations
CMAKE-LISTS.txt
file (GLOB headers "*.h") ## retrieve all header files in current directory
file (GLOB sources "*.cpp") ## retrieve all source files in current directory I had added Executable path and Library path.
file (GLOB instruction_headers "instructions/*.h") ## retrieve all header files in instructions directory
file (GLOB instruction_sources "instructions/*.cpp") ## retrieve all source files in instructions directory
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(mfast_SRCS ${sources} ${instruction_sources} ${headers} ${instruction_headers})
add_library(mfast_static STATIC ${mfast_SRCS})
target_include_directories(mfast_static PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
if (UNIX)
set_target_properties(mfast_static PROPERTIES OUTPUT_NAME mfast)
endif()
set_target_properties(mfast_static PROPERTIES COMPILE_FLAGS -DMFAST_STATIC_DEFINE)
install(TARGETS mfast_static
EXPORT mFASTTargets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib)
set(MFAST_STATIC_LIBRARIES ${MFAST_STATIC_LIBRARIES} mfast_static CACHE INTERNAL "")
if (BUILD_SHARED_LIBS)
add_library(mfast SHARED ${mfast_SRCS})
if (NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.12")
target_compile_definitions(mfast INTERFACE "-DMFAST_DYN_LINK")
endif (NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.12")
if (CMAKE_COMPILER_IS_GNUCXX OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
set_target_properties(mfast PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
endif()
set_target_properties(mfast PROPERTIES
VERSION "${MFAST_VERSION}"
SOVERSION "${MFAST_SOVERSION}")
install(TARGETS mfast
EXPORT mFASTTargets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib)
set(MFAST_SHARED_LIBRARIES ${MFAST_SHARED_LIBRARIES} mfast CACHE INTERNAL "")
endif (BUILD_SHARED_LIBS)
add_subdirectory (coder)
add_subdirectory (xml_parser)
add_subdirectory (json)
if (BUILD_SQLITE3)
add_subdirectory (sqlite3)
endif(BUILD_SQLITE3)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DESTINATION "${INSTALL_INCLUDE_DIR}"
FILES_MATCHING PATTERN "*.h")
Error Log file
CMake Error at mfast/CMakeLists.txt:20 (install):
install TARGETS given no ARCHIVE DESTINATION for static library target
"mfast_static".
CMake Error at mfast/coder/CMakeLists.txt:28 (install):
install TARGETS given no ARCHIVE DESTINATION for static library target
"mfast_coder_static".
CMake Error at mfast/xml_parser/CMakeLists.txt:22 (install):
install TARGETS given no ARCHIVE DESTINATION for static library target
"mfast_xml_parser_static".
CMake Error at mfast/json/CMakeLists.txt:19 (install):
install TARGETS given no ARCHIVE DESTINATION for static library target
"mfast_json_static".
CMake Error at fast_type_gen/CMakeLists.txt:18 (install):
install TARGETS given no RUNTIME DESTINATION for executable target
"fast_type_gen".
CMake Warning (dev) at CMakeLists.txt:5 (set):
Cannot set "FAST_TYPE_GEN_INSTALL_LOCATION": current scope has no parent.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error at CMakeLists.txt:7 (install):
install FILES given no DESTINATION!
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.12)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
Configuring incomplete, errors occurred!
See also "D:/Mihir/mFastVisualStudioProject/CMakeFiles/CMakeOutput.log".
what I have tried:
Added Executable Path and Library
Installed Boost-library 1.63 and added in Path,But found no luck whatsoever as you can see i am getting static library file error. Thanking in Advance
I've got some problems with linking against a debug version of my lib. I use CMake to make a library:
project(myLib)
...
add_library(myLib SHARED ${SOURCES})
I launch the build two times to get a release and a debug version of my lib. Then I add 'd' suffix to the name of the debug lib and have myLib.dll and myLibd.dll.
In my app I explicitly link against the debug dll:
project(myApp)
add_executable(myApp WIN32 ${SOURCES})
target_link_libraries(myApp myLibd.dll)
The build finishes successfully, but when I open the resulting exe file with Dependency Walker I get an unresolved dependency to myLib.dll file, even though the debug version (myLibd.dll) is located in the same folder.
So, why does my app try to use the release version of my lib at runtime? And how do I properly link against the debug version?
You should not rename the file manually. Use CMake's CMAKE_DEBUG_POSTFIX variable or the DEBUG_POSTFIX target property instead:
add_library(myLib SHARED ${SOURCES})
set_target_properties(mylib PROPERTIES DEBUG_POSTFIX "d")
[...]
add_executable(myApp WIN32 ${SOURCES})
target_link_libraries(myApp myLib)