I've been trying to use google test on bare metal and followed the slightly harder variant of the website below to precompile google test, obtain the library file and then link it in a project's CMake
https://clarkli86.wordpress.com/2016/01/28/build-googletest-for-baremetal-targets-stm32/
The CMake runs smoothly throughout the project, in which I'm trying to integrate google test, up to the part it starts building google test
The CMakeLists file of the folder containing the tests and google test looks like this:
set(BINARY ${CMAKE_PROJECT_NAME}_tst)
set(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest/)
add_executable(${BINARY} ${SOURCE})
add_test(NAME ${BINARY} COMMAND ${BINARY})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include/gtest)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include/gtest)
target_link_libraries(${BINARY} PUBLIC Library gtest)
which gives the following error:
SDK_test/testing/main.cpp:3:25: fatal error: gtest/gtest.h: No such file or directory
compilation terminated.
make[2]: *** [testing/CMakeFiles/SdkTest_tst.dir/build.make:63: testing/CMakeFiles/SdkTest_tst.dir/main.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:9691: testing/CMakeFiles/SdkTest_tst.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
On the main.cpp file, gtest is called using:
#include <gtest/gtest.h>
I've tried to build the project using this flag:
-l/testing/googletest/googletest/include/gtest
include the path directly in the CMakeLists, and all result in the error above
If I uncomment the add_subdirectory line, the make build fails due to the pthreads and sleep libraries
examples:
testing/googletest/googletest/include/gtest/internal/gtest-port.h:1453:24: error: 'nanosleep' was not declared in this scope
nanosleep(&time, NULL);
testing/googletest/googletest/include/gtest/internal/gtest-port.h:1499:3: error: 'pthread_mutex_t' does not name a type
pthread_mutex_t mutex_;
Any suggestions on how to properly link the library?
Related
I have a test cmake C++ app, that I can compile successfully with clang++-10 on Ubuntu 20.04 (with all that CMAKE_USER_MAKE_RULES_OVERRIDE machinery).
The layout of the cmake project is:
./test.cpp
./CMakeLists.txt
./build
I also create the build database json file with CMAKE_EXPORT_COMPILE_COMMANDS inside ./build (this json file is necessary for the clang-check operation AFAIU).
Now, launched from the build dir, the check invocation fails:
clang-check-10 --analyze ../test.cpp
<projDir>/test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Error while processing <projDir>/test.cpp.
Any ideas how to fix this?
Edit: Have also tried specifying -p=$(pwd) to clang-check, but it still could not find the header.
clang-check is not a compiler. It's used for checking error in AST, and in this case it can't find the system header in your code. Add '--' in the end of line to ignore it.
clang-check-10 --analyze ../test.cpp
For more information: ClangCheck on LLVM
I am trying to build a custom kernel with Renderscript in Android native development. But got stuck at the compilation step. I took reference with the https://github.com/rpattabi/renderscript-ndk-cmake. Below is my CMakeList.txt
cmake_minimum_required(VERSION 3.4.1)
if(${CMAKE_BUILD_TYPE} MATCHES Release)
set (SRC_RS_GENERATED_PATH
build/generated/source/rs/release)
else()
set (SRC_RS_GENERATED_PATH
build/generated/source/rs/debug)
endif()
set(RENDER_SCRIPT_HEADERS_PATH ${CMAKE_ANDROID_NDK}/toolchains/renderscript/prebuilt/${ANDROID_HOST_TAG}/platform/rs)
include_directories(
${RENDER_SCRIPT_HEADERS_PATH}/cpp
${RENDER_SCRIPT_HEADERS_PATH}/scriptc
${RENDER_SCRIPT_HEADERS_PATH}
${SRC_RS_GENERATED_PATH}
)
set(RENDER_SCRIPT_LIB_PATH ${CMAKE_ANDROID_NDK}/toolchains/renderscript/prebuilt/${ANDROID_HOST_TAG}/platform/${ANDROID_SYSROOT_ABI})
find_library(rscript
NAMES RScpp_static libRScpp_static.a
HINTS ${RENDER_SCRIPT_LIB_PATH}/
)
find_library(blasv8
NAMES blasV8 libblasV8.so
HINTS ${RENDER_SCRIPT_LIB_PATH}/)
find_library(rssupport
NAMES libRSSupport.so
HINTS ${RENDER_SCRIPT_LIB_PATH}/)
add_library(
renderscript
SHARED
RenderScript.cpp
threshold.rs
${SRC_RS_GENERATED_PATH}/ScriptC_threshold.cpp #This file is missing <<<<<<<<<<<<<<<
)
target_link_libraries(
renderscript
log
${rscript}
${rssupport}
${blasv8}
android
jnigraphics
)
The first few parts are just finding the headers for prebuilt library for renderscript in the Android NDK.
The error comes at building the renderscript library part. It suppose to build the threshold.rs file, and generate a header and cpp pair (ScriptC_threshold.h and ScriptC_threshold.cpp), which the source code for renderscript will include.
However, the build script does not generate the ScriptC_threshold.h headers. What is the procedure or CMakeList configuration that allows me to generate the header file from rs files?
Update 1
As suggested by Dan, I change the build script from cmakeList to Android.mk. However, I got another error
[x86] Compile RS : renderscript <= threshold.rs
error: error opening 'E:/dev/android/RenderScriptMk/app/E:/dev/android/RenderScriptMk/app/build/intermediates/ndkBuild/debug/obj/local/x86/objs-debug/renderscript/\threshold.bc': Invalid argument
make: *** [E:/dev/android/RenderScriptMk/app/build/intermediates/ndkBuild/debug/obj/local/x86/objs-debug/renderscript/threshold.o] Error 1
It appears the build process failed to generate the .bc file from the .rs script. I am stuck again. I uploaded my code to Github, it should be able to reproduce.
I'm trying to build Tensorflow on Windows 7 x64 using the guide published here, however, when invoking MSBuild to build TensorFlow (step 4), I get a "Build FAILED" message followed by several errors.
The first:
CUSTOMBUILD : CMake error : CMake can not determine linker language for target: grpc [grpc.vcxproj]
CUSTOMBUILD : CMake error : CMake can not determine linker language for target: grpc_unsecure [grpc.vcxproj]
CUSTOMBUILD : CMake error : CMake can not determine linker language for target: cares [grpc.vcxproj]
does not make sense because within my grpc CMakelists.txt I have the following defined:
set(PACKAGE_NAME "grpc")
project(${PACKAGE_NAME} C CXX)
The other errors all involve source directories not containing a CMakelists.txt file:
CUSTOMBUILD : CMake error : The source directory "C:/tf-dev/local_repos/cub-1.6.4" does not appear to contain CMakeLists.txt. [cub.vcxproj]
which occurs for the following external projects:
cub
farmhash
fft2d
gemmlowp
gif
highwayhash
jpeg
lmdb
However, the Tensorflow build guide does not make any reference to creating additional CMakelists.txt for the externally added projects. Any idea where I might be going wrong? Thanks.
I feel completely lost trying to get CMake to work on Windows. I have a project (ECCODES) that has Fortran and C files. I can compile Fortran files if I don't use CMake. But this project came with a ton of CMake files. I look at the error below and it says to me, "I (CMake) cannot compile a simple Fortran program even though you can compile Fortran files when you aren't using CMake." Can anyone make sense of this? I'm trying to use mingw64 since I can't use cygwin on this project for the Windows build. On Mac OS X and GNU/Linux everything builds fine, but I have to run this project on Windows...
Error:The Fortran compiler "c:/gcc-5.1.0-tdm64-1-fortran/bin/gfortran.exe" is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/knauthg/.CLion2016.1/system/cmake/generated/ECCodes-45f4e5f3/45f4e5f3/__default__/CMakeFiles/CMakeTmp
Run Build Command:"C:/mingw64/bin/mingw32-make.exe" "cmTC_93cb8/fast"
C:/mingw64/bin/mingw32-make.exe -f CMakeFiles\cmTC_93cb8.dir\build.make CMakeFiles/cmTC_93cb8.dir/build
mingw32-make.exe[1]: Entering directory 'C:/Users/knauthg/.CLion2016.1/system/cmake/generated/ECCodes-45f4e5f3/45f4e5f3/__default__/CMakeFiles/CMakeTmp'
Building Fortran object CMakeFiles/cmTC_93cb8.dir/testFortranCompiler.f.obj
c:\gcc-5.1.0-tdm64-1-fortran\bin\gfortran.exe -c C:\Users\knauthg\.CLion2016.1\system\cmake\generated\ECCodes-45f4e5f3\45f4e5f3\__default__\CMakeFiles\CMakeTmp\testFortranCompiler.f -o CMakeFiles\cmTC_93cb8.dir\testFortranCompiler.f.obj
CMakeFiles\cmTC_93cb8.dir\build.make:64: recipe for target 'CMakeFiles/cmTC_93cb8.dir/testFortranCompiler.f.obj' failed
mingw32-make.exe[1]: *** [CMakeFiles/cmTC_93cb8.dir/testFortranCompiler.f.obj] Error 1
mingw32-make.exe[1]: Leaving directory 'C:/Users/knauthg/.CLion2016.1/system/cmake/generated/ECCodes-45f4e5f3/45f4e5f3/__default__/CMakeFiles/CMakeTmp'
Makefile:125: recipe for target 'cmTC_93cb8/fast' failed
mingw32-make.exe: *** [cmTC_93cb8/fast] Error 2
CMake will not be able to correctly generate this project.
Before, I was using the tdm-gcc Windows 64-bit build of gfortran. I switched to the 64-bit build of gfortran by Simply Fortran, and now the entire ECCODES project builds to completion using CMake. I'm still using MingW64 gcc to compile the C files.
Hat tip to John Wasilewski on a thread of Physics Forums who gave the tip about Simply Fortran.
In my header-only library I have the following CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.11)
project(Math)
set(PROJECT_VERSION 0.1)
# Install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX /usr/local)
endif()
message("++ Installation prefix set to \"${CMAKE_INSTALL_PREFIX}\"")
configure_file("${CMAKE_SOURCE_DIR}/pkg-config.pc.cmake"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Math")
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/pkgconfig/")
It works normally, but it appears that when I say make clean (which I expect to be a no-op, but for which make should return 0), I get
make[1]: *** No rule to make target `clean'. Stop.
make: *** [clean] Error 2
I see that there does exist a clean target in Makefile in the build dir, but it calls for a clean target in CMakeFiles/Makefile2, where it doesn't exist.
I've found that the target is created if I add the following to CMakeLists.txt:
add_custom_target(clean)
But then I get some annoying warnings for any make invocation:
Makefile:150: warning: overriding commands for target `clean'
Makefile:123: warning: ignoring old commands for target `clean'
I.e. for some reason the Makefile gets two instances of clean target.
How can I create a no-op clean target cleanly, not getting any warnings?
Adding
add_custom_target(dummy_target)
works for me: make clean doesn't issue any error.
Because ALL is not used for custom target, it doesn't appear during make invocation.