Cmake Strange Error: Syntax Error Unexpected Token (' - c++

I am compiling Qt5, VTK, PCL, and PDAL into a project, and my build process was working excellently until I rebuilt PCL because I was trying to get rid of another weird error where syntax errors kept popping up in Qt5 after linking PCL. For more info on that, see here: Qt, VTK, PCL, and PDAL integration
I also recently agreed to a new XCode License under root. So that may also be the problem. Here is the exact error:
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `/usr/bin/g++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/Users/wfehrnstrom/build-CmakeTest-MainKit-Release -I/Users/wfehrnstrom/CmakeTest -I/usr/local/include/vtk-7.0 -isystem /usr/local/include -iframework /Users/wfehrnstrom/Qt5/5.7/clang_64/lib -isystem /Users/wfehrnstrom/Qt5/5.7/clang_64/lib/QtWidgets.framework/Headers -isystem /Users/wfehrnstrom/Qt5/5.7/clang_64/lib/QtGui.framework/Headers -isystem /System/Library/Frameworks/OpenGL.framework/Headers -isystem /Users/wfehrnstrom/Qt5/5.7/clang_64/lib/QtCore.framework/Headers -isystem /Users/wfehrnstrom/Qt5/5.7/clang_64/./mkspecs/macx-clang -ferror-limit=0 -O3 -DNDEBUG vtkDomainsChemistry_AUTOINIT=1(vtkDomainsChemistryOpenGL2) vtkRenderingContext2D_AUTOINIT=1(vtkRenderingContextOpenGL2) vtkRenderingCore_AUTOINIT=3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2) vtkRenderingVolume_AUTOINIT=1(vtkRenderingVolumeOpenGL2) -fPIC -std=gnu++11 -o CMakeFiles/CmakeTest.dir/main.cpp.o -c /Users/wfehrnstrom/CmakeTest/main.cpp'
make[2]: *** [CMakeFiles/CmakeTest.dir/main.cpp.o] Error 2
make[1]: *** [CMakeFiles/CmakeTest.dir/all] Error 2
make: *** [all] Error 2
Does anyone know why I am getting this strange error seemingly out of nowhere after rebuilding VTK and PCL? Thank you!

Had this exact same issue when pulling PCL into QT5 on OS X.
Compiling PCL 1.8 from source resolved the issue (migrated from PCL 1.6).
CMakeLists.txt:
project(LRS_PCL)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
cmake_minimum_required(VERSION 2.8)
set(SOURCE_DIR .)
set(SOURCE
${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
PARENT_SCOPE
)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt/5.5/gcc_64)
find_package( PCL 1.8 REQUIRED )
find_package( Qt5 REQUIRED COMPONENTS Widgets Core )
include( CheckCXXCompilerFlag )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
include_directories( ${PCL_INCLUDE_DIRS} /user/local/include )
link_directories( ${PCL_LIBRARY_DIRS} /usr/local/lib /usr/lib/x86_64-linux-gnu )
add_definitions( ${PCL_DEFINITIONS} )
target_link_libraries( LRS_PCL ${PCL_LIBRARIES} /usr/local/lib/librealsense.so )

Related

C++: Problem with M1 architecture in cmake: how do I change the architecture?

I am trying to run cmake command in the new environment.
Upon running cmake . . I get clang: error: the clang compiler does not support '-march=core2' error. I tried to run it with cmake '-DCMAKE_CXX_FLAGS='-march=x86-64'' flag, and it changed the march for a while but only in CLion IDE and only when I was doing that continuously. I can't seem to make it work in the terminal while reading different makefile.
Full error when I run either cmake or ```cmake '-DCMAKE_CXX_FLAGS='-march=x86-64'':
Determining if the C compiler works failed with the following output:
Change Dir: /Users/marcin/CLionProjects/pythontest5/CMakeFiles/CMakeTmp
Run Build Command(s):/Library/Developer/CommandLineTools/usr/bin/make -f Makefile cmTC_925c1/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_925c1.dir/build.make CMakeFiles/cmTC_925c1.dir/build
Building C object CMakeFiles/cmTC_925c1.dir/testCCompiler.c.o
/Library/Developer/CommandLineTools/usr/bin/gcc -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /opt/homebrew/anaconda3/include -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -MD -MT CMakeFiles/cmTC_925c1.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_925c1.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_925c1.dir/testCCompiler.c.o -c /Users/marcin/CLionProjects/pythontest5/CMakeFiles/CMakeTmp/testCCompiler.c
clang: error: the clang compiler does not support '-march=core2'
make[1]: *** [CMakeFiles/cmTC_925c1.dir/testCCompiler.c.o] Error 1
make: *** [cmTC_925c1/fast] Error 2
My CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(automobile VERSION 0.1.0)
# Include dir
include_directories(/usr/local/include)
# Src
AUX_SOURCE_DIRECTORY(src SRC_FILES)
# Headers
set(PROJECT_SOURCE_DIR "src")
set(PROJECT_INCLUDE_DIR "include/automobile_bits")
# Source files
set(SOURCE_FILES
${PROJECT_INCLUDE_DIR}/motorcycle.hpp
${PROJECT_SOURCE_DIR}/motorcycle.cpp
)
# Set up such that XCode organizes the files correctly
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES})
# Add library
add_library(automobile SHARED ${SOURCE_FILES})
# Include directories
target_include_directories(automobile PRIVATE include/automobile_bits)
# Install
install(TARGETS automobile DESTINATION lib)
# Install the headers
install(FILES include/automobile DESTINATION include)
# Create base directory
install(DIRECTORY include/automobile_bits DESTINATION include)
It's unclear where cmake gets -march=core2 from. Try to remove CMakeCache.txt then re-run cmake ..
If it does not help, try to remove CMakeCache.txt and run cmake . -DCMAKE_OSX_ARCHITECTURES=arm64.

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 cannot find QGLWidget

I have a simple bouncing ball program that I wrote in QtCreator on Windows a couple years ago, and now I'm trying to rebuild it on Linux (Ubuntu 14.04) using CMakeLists instead of the Qt project files. My CMakeLists.txt file (loosely based off the cmake file in this question is below.
cmake_minimum_required ( VERSION 2.6 )
project ( BouncyBall )
find_package ( Qt4 COMPONENTS QtGui QtOpenGL REQUIRED )
set (QT_USE_QTOPENGL TRUE)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
include_directories( ${QT_QTOPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} )
find_package ( Bullet REQUIRED )
add_executable ( BouncyBall main.cpp BouncyBall.cpp BulletWidget.cpp )
target_link_libraries( BouncyBall ${QT_LIBRARIES} ${BULLET_LIBRARIES} )
Cmake configures and generates the build files without any errors, but fails to compile with the following error:
[ 33%] Building CXX object CMakeFiles/BouncyBall.dir/main.cpp.o
/usr/bin/c++ -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtOpenGL -isystem /usr/include/qt4/QtGui -I/home/user/Programs/BuildArea/Games/BouncyBall -o CMakeFiles/BouncyBall.dir/main.cpp.o -c /home/user/Programs/Games/BouncyBall/main.cpp
In file included from /home/user/Programs/Games/BouncyBall/main.cpp:2:0:
/home/user/Programs/Games/BouncyBall/BulletWidget.h:4:30: fatal error: QtOpenGl/QGLWidget: No such file or directory
#include <QtOpenGl/QGLWidget>
I've verified that the file is indeed in /usr/include/qt4/QtOpenGL. I've looked online, but all the solutions I've found refer to adding QT += opengl to a project file (but I'm using CMake) or to not having the dev-tools or qt-sdk packages installed (which I do have).
What am I missing?
Isn't there a typo in your code 'QtOpenGl/QGLWidget'? QtOpenGl should be changed to QtOpenGL. If you do it on Linux the case matters.

cmake generates wrong makefiles

/usr/bin/clang++ -std=c++11;-Werror;-Wextra;-Wall;-Wconversion -g -o CMakeFiles/TilingGame.dir/src/streak.cc.o -c /home/arne/projects/tilinggame/src/streak.cc
clang: error: no input files
/bin/sh: -Werror: Kommando nicht gefunden.
/bin/sh: -Wextra: Kommando nicht gefunden.
/bin/sh: -Wall: Kommando nicht gefunden.
/bin/sh: -Wconversion: Kommando nicht gefunden.
CMakeFiles/TilingGame.dir/build.make:54: recipe for target 'CMakeFiles/TilingGame.dir/src/streak.cc.o' failed
as you can see my shees sees the semicolon as the end of the command and then tries to interpret "-Werror" as a new command. How can I tell cmake to generate working makefiles instead of broken ones?
here is my CMakeLists.txt
project(TilingGame)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(src SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
set(CMAKE_CXX_FLAGS -std=c++11 -Werror -Wextra -Wall -Wconversion)
include(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image)
PKG_SEARCH_MODULE(SDL2MIXER REQUIRED SDL2_mixer)
PKG_SEARCH_MODULE(SDL2TTF REQUIRED SDL2_ttf)
PKG_SEARCH_MODULE(ZLIB REQUIRED zlib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2MIXER_LIBRARIES} ${SDL2TTF_LIBRARIES} ${ZLIB_LIBRARIES} tmxparser tinyxml)
Since you don't show us the section of your cmake file where you are adding those flags we can't say exactly. However, clearly somehow you're causing cmake to convert a list of values into a string and then using that string as flags. The string-ified version of list variables in cmake are semicolon-separated.
For example maybe you have something like this in your CMakeLists.txt:
set(FLAGS -std=c++11 -Werror -Wextra -Wall -Wconversion)
add_definitions("${FLAGS}")
You should not use the quotes here.
You can only add strings/append strings to CMAKE_CXX_FLAGS, but not lists.
The following should work:
set(CMAKE_CXX_FLAGS "-std=c++11 -Werror -Wextra -Wall -Wconversion")

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})