Could NOT find wxWidgets (missing: wxWidgets_FOUND) - c++

I am working an a hello-world level program using wxWidgets in Ubuntu.
The code compiles with
g++ HelloWorld.cpp `wx-config --libs` `wx-config --cxxflags` -o HelloWorldApp -I../inc
maot#HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$ which wx-config
/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/wx-config
maot#HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$
...which makes sense because I put the path to wx-config in the PATH environment variable. I compiled wxWidgets myself.
Now I want to use cmake. My CMakeLists.txt file attempt:
cmake_minimum_required(VERSION 2.8.9)
project(WxWidgets_Learning_01)
set(CMAKE_CXX_COMPILER /usr/bin/g++)
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG " -g3 ")
set(CMAKE_CXX_FLAGS_RELEASE "")
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
include_directories(../inc)
include_directories(../api/IBJts/source/cppclient/client)
include_directories(../api/IBJts/source/cppclient)
# wxWidgets header files start
include_directories(/home/maot/Perforce/wxWidgets-3.1.0/include)
include_directories(/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib/wx/include/gtk2-unicode-3.1)
# wxWidgets header files end
# wxWidgets defines start
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__)
# wxWidgets defines finish
# Directories with wxWidget libs start
link_directories(/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib)
# Directories with wxWidget libs finish
SET(wxWidgets_ROOT_DIR /home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib)
SET(wxWidgets_CONFIGURATION mswud)
# https://cmake.org/cmake/help/v3.0/module/FindwxWidgets.html
# Note that for MinGW users the order of libs is important!
find_package(wxWidgets COMPONENTS net gl core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -pthread -lm ")
file(GLOB sources "../src/*.cpp" )
file(GLOB headers "../inc/*.h" )
set(daytrading_sources ${sources} ${headers})
add_executable(WxWidgets_Learning_01 ${sources})
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
Output:
maot#HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$ \rm -rf CMakeFiles/ ; cmake .
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMAKE_CXX_FLAGS_DEBUG = -g
CMAKE_CXX_FLAGS_RELEASE = -O3 -DNDEBUG
CMAKE_CXX_FLAGS_DEBUG = -g3
CMAKE_CXX_FLAGS_RELEASE =
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find wxWidgets (missing: wxWidgets_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindwxWidgets.cmake:832 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:40 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/maot/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src/CMakeFiles/CMakeOutput.log".
maot#HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$
I think find_package can not find wxWidgets and I do not understand why. I am uncertain about this mswud thing because I can not find explanations about it; ms sounds like Bill G. I have tried a few values for wxWidgets_ROOT_DIR but no luck. Any help is welcome: What value should wxWidgets_ROOT_DIR have, and is mswud any good?
=== Edit below ===
I followed https://wiki.wxwidgets.org/Compiling_and_getting_started, using the --prefix=$(pwd) option. make install is not needed, it sais.
How to put the results of wx-config in CMakeLists.txt?
maot#HP-Pavilion-dv7:~$ wx-config --cxxflags
-I/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib/wx/include/gtk2-unicode-3.1 -I/home/maot/Perforce/wxWidgets-3.1.0/include -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread
maot#HP-Pavilion-dv7:~$
maot#HP-Pavilion-dv7:~$ wx-config --libs
-L/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib -pthread -Wl,-rpath,/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib -lwx_gtk2u_xrc-3.1 -lwx_gtk2u_html-3.1 -lwx_gtk2u_qa-3.1 -lwx_gtk2u_adv-3.1 -lwx_gtk2u_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1
maot#HP-Pavilion-dv7:~$
I got my code compiling and running using the CMakeLists.txt file below; I realise it is not the way things are intended.
cmake_minimum_required(VERSION 2.8.9)
project(WxWidgets_Learning_01)
set(CMAKE_CXX_COMPILER /usr/bin/g++)
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG " -g3 ")
set(CMAKE_CXX_FLAGS_RELEASE "")
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
include_directories(../inc)
include_directories(../api/IBJts/source/cppclient/client)
include_directories(../api/IBJts/source/cppclient)
# wxWidgets header files start
include_directories(../../../../wxWidgets-3.1.0/include)
include_directories(../../../../wxWidgets-3.1.0/gtk-build/lib/wx/include/gtk2-unicode-3.1)
# wxWidgets header files end
# wxWidgets defines start
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__)
# wxWidgets defines finish
# Directories with wxWidget libs start
link_directories(../../../../wxWidgets-3.1.0/gtk-build/lib)
# Directories with wxWidget libs finish
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -pthread -lm ")
file(GLOB sources "../src/*.cpp" )
file(GLOB headers "../inc/*.h" )
set(daytrading_sources ${sources} ${headers})
add_executable(WxWidgets_Learning_01 ${sources})
target_link_libraries(WxWidgets_Learning_01
libwx_baseu-3.1.so
libwx_gtk2u_adv-3.1.so
libwx_gtk2u_gl-3.1.so
libwx_gtk2u_qa-3.1.so
libwx_gtk2u_stc-3.1.so
libwx_baseu_net-3.1.so
libwx_gtk2u_aui-3.1.so
libwx_gtk2u_html-3.1.so
libwx_gtk2u_ribbon-3.1.so
libwx_gtk2u_xrc-3.1.so
libwx_baseu_xml-3.1.so
libwx_gtk2u_core-3.1.so
libwx_gtk2u_propgrid-3.1.so
libwx_gtk2u_richtext-3.1.so
)
# I have just added all .so files that I found after the build.

If you need to compile just a simple example for the prototype then thats it.
However, if you need to compile some big project - you can try to set up Anjuta/CodeBlocks/CodeLite to help. It will benefit you in the long run (especially CodeBlocks).
In terms of your questions: mswud is not good, since it (as name suggested) for Windows.
Also, for the include/lib directory you should use wx-config appropriate command, just as you used for command-line compiling.
You can also try to take a look at CMake effort by TobiasT in trac.wxwidgets.org.

Related

undefined reference to `Example::Note::~Note()' protobuf

I Written a very simple program in protobuf without services at all but when i run the code it throws erros like Example::Note::~Note() all information are given below please tell me where i'm making mistake.
example.proto
syntax = "proto3";
package Example;
message Note {
int32 id = 1;
string title = 2;
string description = 3;
}
i use protoc --cpp_out=. example.proto command to generate auto generated files
main.cpp
#include "example.pb.h"
#include <iostream>
int main(int argc, char const *argv[])
{
Example::Note note;
note.set_id(1);
note.set_title("This is Title");
note.set_description("This is Description");
std::cout << "Note Information: " << note.DebugString() << std::endl;
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(EXAMPLE LANGUAGES CXX)
# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_GRPC_GRPCPP gRPC::grpc++)
set(_REFLECTION gRPC::grpc++_reflection)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
add_executable(Example
main.cpp
)
target_link_libraries(Example
Threads::Threads
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}
)
Error
.
.
.
-- Build files have been written to: /home/react-vision/dev/workingWithProtobuff/simpleExample/build
[ 50%] Building CXX object CMakeFiles/Example.dir/main.cpp.o
[100%] Linking CXX executable Example
/usr/bin/ld: CMakeFiles/Example.dir/main.cpp.o: in function `main':
main.cpp:(.text+0xf4): undefined reference to `Example::Note::~Note()'
/usr/bin/ld: main.cpp:(.text+0x12f): undefined reference to `Example::Note::~Note()'
/usr/bin/ld: CMakeFiles/Example.dir/main.cpp.o: in function `Example::Note::Note()':
main.cpp:(.text._ZN7Example4NoteC2Ev[_ZN7Example4NoteC5Ev]+0x22): undefined reference to `Example::Note::Note(google::protobuf::Arena*, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/Example.dir/build.make:153: Example] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/Example.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
The following CMakeLists.txt is enough for your example.proto and main.cpp file. It does not use gRPC because that wasn't relevant to testing.
cmake_minimum_required(VERSION 3.23)
project(example)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(example_srcs example_hdrs example.proto)
add_executable(main main.cpp ${example_srcs} ${example_hdrs})
target_include_directories(main PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(main PRIVATE protobuf::libprotobuf)
Below is a line-by-line explanation of this build and why it works.
Let's go line by line:
cmake_minimum_required(VERSION 3.23)
This must always be the first line of your top-level CMakeLists.txt file. It tells CMake which policies to enable. This is to ensure backwards compatibility, but not forwards compatibility, i.e. CMake will not emulate older versions, but will simply toggle back to old behaviors in certain cases. In particular, it will not stop you from using features that are too new for the stated minimum version, so you must always test your build with the version listed here. I wrote this answer using 3.23, but it will probably work with older versions.
project(example)
With very few exceptions, this will be the second line for your CMakeLists.txt. You can pick any project name you want. I chose example here because, well, this is an example. This command is what kicks off CMake's compiler detection routines. It is invalid to do most things before that has happened.
find_package(Protobuf REQUIRED)
This project uses protobuf so we use find_package to access CMake's first-party protobuf support (see documentation here). Because the project cannot possibly work without protobuf, we add the REQUIRED argument.
protobuf_generate_cpp(example_srcs example_hdrs example.proto)
Now we call a function provided by the find_package(Protobuf ...) module. This wraps a call to the protobuf compiler and defines two variables, example_srcs and example_hdrs (the names are arbitrary), to hold the files generated from example.proto. This isn't well-documented, but the generated files are placed in ${CMAKE_CURRENT_BINARY_DIR}.
add_executable(main main.cpp ${example_srcs} ${example_hdrs})
Now we create an executable target from your source file (main.cpp) and the aforementioned generated source files.
target_include_directories(main PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
The source files for main need to see the generated sources, so we add ${CMAKE_CURRENT_BINARY_DIR} to the list of include directories.
target_link_libraries(main PRIVATE protobuf::libprotobuf)
Finally, the application needs to link to the protobuf library, so we link to the imported protobuf::libprotobuf target. This, too, was created by the find_package(Protobuf ...) command.
To adjust this build to use Protobuf's own CMake support and to skip CMake's module, you will need to make the following changes:
Add CONFIG to find_package.
Replace the use of protobuf_generate_cpp with protobuf_generate.
This is what the build would look like:
cmake_minimum_required(VERSION 3.23)
project(example)
find_package(Protobuf CONFIG REQUIRED)
add_executable(main main.cpp)
protobuf_generate(TARGET main PROTOS example.proto)
target_include_directories(main PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(main PRIVATE protobuf::libprotobuf)
The CONFIG argument tells CMake to ignore any find modules that match (including its own first-party modules). Then the new command protobuf_generate replaces protobuf_generate_cpp. Now instead of populating source variables, you give it the target for which you're generating sources. The PROTOS argument is the list of protobuf files to compile.
Because it takes the target as an argument, it must follow add_exectuable, rather than precede it.
Here's how I built protobuf from sources to test this:
$ git clone --recursive git#github.com:protocolbuffers/protobuf.git
$ cmake -G Ninja -S protobuf -B _build/protobuf -DCMAKE_BUILD_TYPE=Release -Dprotobuf_BUILD_TESTS=NO -DCMAKE_INSTALL_PREFIX=$PWD/_local
$ cmake --build _build/protobuf/ --target install
Now I can compile the program in this example:
alex#alex-ubuntu:~/test$ cmake -G Ninja -S . -B _build/project -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PWD/_local
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/_build/project
alex#alex-ubuntu:~/test$ cmake --build _build/project/ --verbose
[1/4] cd /home/alex/test/_build/project && /home/alex/test/_local/bin/protoc-3.21.0.2 --cpp_out :/home/alex/test/_build/project -I /home/alex/test /home/alex/test/example.proto
[2/4] /usr/bin/c++ -I/home/alex/test/_build/project -isystem /home/alex/test/_local/include -O3 -DNDEBUG -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d -o CMakeFiles/main.dir/main.cpp.o -c /home/alex/test/main.cpp
[3/4] /usr/bin/c++ -I/home/alex/test/_build/project -isystem /home/alex/test/_local/include -O3 -DNDEBUG -MD -MT CMakeFiles/main.dir/example.pb.cc.o -MF CMakeFiles/main.dir/example.pb.cc.o.d -o CMakeFiles/main.dir/example.pb.cc.o -c /home/alex/test/_build/project/example.pb.cc
[4/4] : && /usr/bin/c++ -O3 -DNDEBUG CMakeFiles/main.dir/main.cpp.o CMakeFiles/main.dir/example.pb.cc.o -o main ../../_local/lib/libprotobuf.a -lpthread /usr/lib/x86_64-linux-gnu/libz.so && :
alex#alex-ubuntu:~/test$ ./_build/project/main
Note Information: id: 1
title: "This is Title"
description: "This is Description"

Undefined reference to 'cudaRegisterLinkedBinary' - linking error in CMake?

I'm running CentOS 7.8 via dual-boot on a 64-bit 2013 Mac with a GT 650M GPU. I'm using CMake 3.17, CUDA 10.0, and GCC 4.8.5. All CUDA samples have been tested and work fine, and I'm able to compile other standard C++ code perfectly.
I've reduced my full project to a simple test case as follows, where the CMakeLists file is:
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
PROJECT(test LANGUAGES CUDA CXX C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
MESSAGE(STATUS "Setting to Release mode")
SET(CMAKE_BUILD_TYPE "Release")
# Set CUDA flags
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_30 -rdc=true")
# Set flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -ffast-math")
MESSAGE(STATUS "Setting g++ flags for Release configuration")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") ## Optimize
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ") ## Strip binary
ADD_SUBDIRECTORY( src )
In the /src folder I have another CMake file to gather the source files:
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
SET(test_SRCS
rsmain.cu
SGP4.cu
SGP4.cuh
)
function(my_add_executable TargetName)
set(Files ${ARGV})
list(REMOVE_AT Files 0)
add_executable(${TargetName} ${Files})
set_target_properties(${TargetName} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_SOURCE_DIR}/build")
endfunction()
my_add_executable(test ${test_SRCS})
INSTALL( TARGETS test DESTINATION bin)
As shown, there are three main source files - both SGP4.cu and SGP4.cuh are empty, while rsmain.cu is simply:
/// Main function
int main(int argc, char *argv[])
{
return 0;
}
When trying to build, I get the following output:
[me#localhost build]$ cmake3 ..
-- The CUDA compiler identification is NVIDIA 10.0.130
-- The CXX compiler identification is GNU 4.8.5
-- The C compiler identification is GNU 4.8.5
-- Check for working CUDA compiler: /usr/local/cuda-10.0/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda-10.0/bin/nvcc - works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- No build configuration specified, defaulting to Release
-- Setting general compiler flags for detected compiler: gnu-g++
-- Setting g++ flags for Release configuration
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/Documents/test/build
[me#localhost build]$ make
/usr/bin/cmake3 -S/home/me/Documents/test -B/home/me/Documents/test/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake3 -E cmake_progress_start /home/me/Documents/test/build/CMakeFiles /home/me/Documents/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/me/Documents/test/build'
make -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/depend
make[2]: Entering directory `/home/me/Documents/test/build'
cd /home/me/Documents/test/build && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /home/me/Documents/test /home/me/Documents/test/src /home/me/Documents/test/build /home/me/Documents/test/build/src /home/me/Documents/test/build/src/CMakeFiles/test.dir/DependInfo.cmake --color=
Scanning dependencies of target test
make[2]: Leaving directory `/home/me/Documents/test/build'
make -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/build
make[2]: Entering directory `/home/me/Documents/test/build'
[ 33%] Building CUDA object src/CMakeFiles/test.dir/rsmain.cu.o
cd /home/me/Documents/test/build/src && /usr/local/cuda-10.0/bin/nvcc -I/home/me/Documents/test/src -I/home/me/Documents/test/build/src -I/home/me/Documents/test/build -arch=sm_30 -rdc=true -O3 -DNDEBUG -std=c++03 -x cu -c /home/me/Documents/test/src/rsmain.cu -o CMakeFiles/test.dir/rsmain.cu.o
[ 66%] Building CUDA object src/CMakeFiles/test.dir/SGP4.cu.o
cd /home/me/Documents/test/build/src && /usr/local/cuda-10.0/bin/nvcc -I/home/me/Documents/test/src -I/home/me/Documents/test/build/src -I/home/me/Documents/test/build -arch=sm_30 -rdc=true -O3 -DNDEBUG -std=c++03 -x cu -c /home/me/Documents/test/src/SGP4.cu -o CMakeFiles/test.dir/SGP4.cu.o
[100%] Linking CUDA executable ../test
cd /home/me/Documents/test/build/src && /usr/bin/cmake3 -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/g++ -s CMakeFiles/test.dir/rsmain.cu.o CMakeFiles/test.dir/SGP4.cu.o -o ../test -lcudadevrt -lcudart_static -L"/usr/local/cuda-10.0/targets/x86_64-linux/lib/stubs" -L"/usr/local/cuda-10.0/targets/x86_64-linux/lib" -lcudadevrt -lcudart_static -lrt -lpthread -ldl
CMakeFiles/test.dir/rsmain.cu.o: In function `__sti____cudaRegisterAll()':
tmpxft_00004eed_00000000-5_rsmain.cudafe1.cpp:(.text.startup+0x25): undefined reference to `__cudaRegisterLinkedBinary_41_tmpxft_00004eed_00000000_6_rsmain_cpp1_ii_main'
CMakeFiles/test.dir/SGP4.cu.o: In function `__sti____cudaRegisterAll()':
tmpxft_00004f02_00000000-5_SGP4.cudafe1.cpp:(.text.startup+0x15): undefined reference to `__cudaRegisterLinkedBinary_39_tmpxft_00004f02_00000000_6_SGP4_cpp1_ii_71922fcb'
collect2: error: ld returned 1 exit status
make[2]: *** [test] Error 1
make[2]: Leaving directory `/home/me/Documents/test/build'
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make[1]: Leaving directory `/home/me/Documents/test/build'
make: *** [all] Error 2
Could anyone please explain what this 'cudaRegisterLinkedBinary' stuff is all about? I've tried a bunch of things in trying to solve it but nothing has worked so far. Is there an issue with any of the package versions? A problem in CMakeLists? Compatibility issues with CUDA and my hardware?
It's worth noting that the full code compiled and ran perfectly when I tested it on a HPC server (also running CentOS 7 and Cuda 10.0) - but on my personal PC it fails at the linking step. I've even confirmed that the .bashrc files are the same across both installations, but it hasn't fixed anything. I'm also currently able to compile NVIDIA's OptiX software (which also uses CUDA) without any problems.
Any advice would be appreciated. Please let me know if I missed any required details.
EDIT: Answer added below. Resolved.
Finally sorted this out. This was my main CMakeLists file:
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
PROJECT(test LANGUAGES C CXX CUDA)
SET(CMAKE_BUILD_TYPE "Release")
# Set CUDA flags
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_30 -rdc=true")
# Set flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -ffast-math -O3")
MESSAGE(STATUS "Setting g++ flags for Release configuration")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s") ## Strip binary
ADD_SUBDIRECTORY( src )
And in the /src CMakeLists file, I had to make the change:
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
SET(test_SRCS
rsmain.cu
SGP4.cu
SGP4.cuh
)
function(my_add_executable TargetName)
set(Files ${ARGV})
list(REMOVE_AT Files 0)
add_executable(${TargetName} ${Files})
set_target_properties(${TargetName} PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON
RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_SOURCE_DIR}/build")
endfunction()
my_add_executable(test ${test_SRCS})
INSTALL( TARGETS test DESTINATION bin)
Setting CUDA_RESOLVE_DEVICE_SYMBOLS to ON is the change. In my main project, I also had to repeat this for every target involving any CUDA files. Everything compiles and runs perfectly now.

Qt Creator + CMake + Clang

I am trying to use Qt Creator to work on a non-Qt C++ program, built using CMake with Clang as the compiler. Platform is Windows 10 64. All versions are most recent at time of this post. After manually downloading Jom and adding it to the path, I get this error trying to build a Hello World program:
The C compiler identification is Clang 6.0.0
The CXX compiler identification is Clang 6.0.0
Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe
Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/Program Files/LLVM/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/Alex/AppData/Local/Temp/QtCreator-zKOojN/qtc-cmake-TXXABrTJ/CMakeFiles/CMakeTmp
Run Build Command:"jom" "/nologo" "cmTC_75f57\fast"
jom: parallel job execution disabled for Makefile
C:\apps\Jom\jom.exe -f CMakeFiles\cmTC_75f57.dir\build.make /nologo -L CMakeFiles\cmTC_75f57.dir\build
Building C object CMakeFiles/cmTC_75f57.dir/testCCompiler.c.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe #C:\Users\Alex\AppData\Local\Temp\testCCompiler.c.obj.12652.16.jom
Linking C executable cmTC_75f57.exe
"C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_75f57.dir --manifests -- llvm-ld /nologo #CMakeFiles\cmTC_75f57.dir\objects1.rsp #C:\Users\Alex\AppData\Local\Temp\cmTC_75f57.exe.12652.297.jom
RC Pass 1: command "rc /foCMakeFiles\cmTC_75f57.dir/manifest.res CMakeFiles\cmTC_75f57.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the file specifiedjom: C:\Users\Alex\AppData\Local\Temp\QtCreator-zKOojN\qtc-cmake-TXXABrTJ\CMakeFiles\CMakeTmp\CMakeFiles\cmTC_75f57.dir\build.make [cmTC_75f57.exe] Error 2
jom: C:\Users\Alex\AppData\Local\Temp\QtCreator-zKOojN\qtc-cmake-TXXABrTJ\CMakeFiles\CMakeTmp\Makefile [cmTC_75f57\fast] Error 2
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
SET (CMAKE_C_COMPILER "clang-cl")
SET (CMAKE_C_FLAGS "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_CXX_COMPILER "clang-cl")
SET (CMAKE_CXX_FLAGS "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_AR "llvm-ar")
SET (CMAKE_LINKER "llvm-ld")
SET (CMAKE_NM "llvm-nm")
SET (CMAKE_OBJDUMP "llvm-objdump")
SET (CMAKE_RANLIB "llvm-ranlib")
project(TestProg)
add_executable(${PROJECT_NAME} "main.cpp")

CMake-based build of CUDA app fails - no files passed to linker

I'm trying to use CMake with a CUDA project of mine, but I'm having trouble getting it to build the executable when compiled on a system that has a CUDA-enabled device.
The CMakeLists.txt in question is below. It supports systems with and without CUDA-enabled devices, and builds just fine on my Macbook which doesn't have CUDA.
cmake_minimum_required (VERSION 2.8)
message(STATUS "CMake version: ${CMAKE_VERSION}")
project(stockModel)
# Grab the CUDA package
find_package(CUDA)
set(GPU_ACCELERATED ${CUDA_FOUND})
# Set directory and compilation flags for both g++ and nvcc
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}
-gencode arch=compute_50,code=sm_50; -std=c++11; -lcurand;"
)
set(CUDA_PROPAGATE_HOST_FLAGS off)
# Add directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/build/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/core/)
if (${GPU_ACCELERATED})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/support/)
endif()
# Setup environments, depending on GPU accel. status
set(SRCS build/main.cpp core/callModels.cpp)
set(INCS core/callModels.h)
if (${GPU_ACCELERATED})
set(SRCS ${SRCS} support/prng.cu support/debugCFP.cu)
set(INCS ${INCS} support/prng.h support/debugCFP.h)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/core/callModels.cpp
PROPERTIES CUDA_SOURCE_PROPERTY_FORMAT OBJ
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
-L/usr/local/cuda/lib64 -lcuda -lcudart"
)
endif()
# Create executable
message(STATUS "Sources: ${SRCS}")
message(STATUS "Includes: ${INCS}")
cuda_add_executable(stockModel ${SRCS} ${INCS})
The error I get when I attempt to build on my Jetson TX1 is as follows:
...
[ 80%] Building CXX object CMakeFiles/stockModel.dir/main.cpp.o
[100%] Linking CXX executable stockModel
c++: fatal error: no input files
compilation terminated.
...
Any ideas as to what is going wrong here? Obviously it has something to do with the CUDA 'extras', but I'm at a loss as to what is causing this.
Let me know if you need more details.
Here is the relevant part of the verbose output:
...
[100%] Linking CXX executable stockModel
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/stockModel.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 -pthread
c++: fatal error: no input files
compilation terminated.
I've uploaded the full make VERBOSE=1 output to this gist on GitHub.
CMake is sometimes finicky about spaces and list combinations. I know that doesn't sound like much of an explanation, but I'm not much of an expert.
What you need to do is replace this:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
-L/usr/local/cuda/lib64 -lcuda -lcudart"
with this:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/cuda/lib64 -lcuda -lcudart")
(single line). That should do it. At least - it does on my system (I created dummy source files with your files' names to try this out).

CMake libraries issue

I'm trying to compile a program that uses the URG (Laser scanner) library along with PCL. URG uses make to build but PCL uses cmake. I've been trying to use cmake for both but i've been having issues.
I found FindURG.cmake and put it in the modules folder here: https://github.com/wicron/vlidar/blob/master/cmake/FindURG.cmake
My CMakeLists is:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
find_package(URG REQUIRED)
include_directories(${URG_INCLUDE_DIR})
link_directories(${URG_LIBRARY})
#add_executable(pcd_write_test pcd_write.cpp)
add_executable(urg_read_test gdScanSample.cpp)
#target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})
target_link_libraries(urg_read_test ${URG_LIBRARY})
SET(CMAKE_C_FLAGS "-I/usr/local/include/urg")
#SET(CMAKE_CXX_FLAGS "-I/usr/local/include/urg")
PCL is found fine, URG is also found as shown below. The directories look fine too.
root#CCSL02:/home/marwan/pcl_sample# cmake CMakeLists.txt
-- looking for PCL_COMMON
-- looking for PCL_OCTREE
-- looking for PCL_IO
-- Found c_urg libraries. /usr/local/lib/libc_urg_system.so/usr/local/lib/libc_urg.so/usr/local/lib/libc_urg_connection.so/usr/lib/liburg.so/usr/lib/liburg_connection.so/usr/lib/liburg_system.so/usr/lib/liburg_common.so/usr/lib/liburg_coordinate.so/usr/lib/liburg_geometry.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/marwan/pcl_sample
But as soon as I run make, here's what I get:
root#CCSL02:/home/marwan/pcl_sample# make
[100%] Building CXX object CMakeFiles/urg_read_test.dir/gdScanSample.cpp.o
/home/marwan/pcl_sample/gdScanSample.cpp:10:21: fatal error: UrgCtrl.h: No such file or directory compilation terminated.
make[2]: *** [CMakeFiles/urg_read_test.dir/gdScanSample.cpp.o] Error 1
make[1]: *** [CMakeFiles/urg_read_test.dir/all] Error 2
make: *** [all] Error 2
I've tried to play with the CMakeLists in which I tried added the CXX flags but no luck
It should be noted that the following makefile compiles the urg program normally
# Makefile for urg_sample
# Satofumi KAMIMURA
# $Id: Makefile 1997 2012-10-30 02:57:51Z satofumi $
CXXFLAGS = -g -O0 -Wall -Werror `urg-config --cflags` `sdl-config --cflags`
LDFLAGS =
LDLIBS = `urg-config --libs` `sdl-config --libs` -lc
TARGET = gdScanSample
all : $(TARGET)
clean :
$(RM) *.o $(TARGET)
.PHONY : all clean
You need to verify that SET(CMAKE_C_FLAGS "-I/usr/local/include/urg") points to the directory where all the h files are. Maybe you will need to add more than one location.
Solved thanks to ComicSansMS
Here's a working CMakeLists.txt:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED)#COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
find_package(URG REQUIRED)
include_directories(${URG_INCLUDE_DIR}/urg)
link_directories(${URG_LIBRARIES})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_LIBRARIES} ${URG_LIBRARIES})