Can't locate c++ executable that g++ just created - c++

This is a baffling issue for me, will be glad if someone has an insight.
I am tasked with converting an existing small c++ project that currently uses makefiles to one that is based on CMAKE. I am through the task, created CMakeLists.txt in all relevant folders and such. I then created a build folder inside the source tree and tried a build after running cmake. Everything builds correctly as it should (first builds 3 libs from other people's code, those are linked to this project's code etc.) and the status "make" command printed does show this. Finally, the command completes 100% with the last line saying [100%] Built target XXXXX
However, that target executable is nowhere to be found! I have tried explicitly setting CMAKE_ARCHIVE_OUTPUT_DIRECTORY to a directory in source (this is how we ideally want), some other folder, not setting it at all, etc. but to no avail. I create this executable using add_executable command and if I instead create a library from the same sources in the same location, the library (.a) gets created fine but I just cant seem to find this executable if I create it that make claims it built.
If it helps, the same project, if built on Windows, creates the EXE fine and I can see/run it in the folder inside source if I so specify.
(I am running g++/cmake on MacOS Sierra on the latest Macbook Pro that has SIP not turned off.)
Here is my minimal CMakeLists. The external libnames are replaced with LLLL. They are external libs in LLLL.a format in the lib directory.
cmake_minimum_required(VERSION 3.0)
project(my_exec C CXX)
cmake_policy(SET CMP0010 NEW)
set(CMAKE_MACOSX_RPATH TRUE)
SET(ENABLE_WARNINGS TRUE)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c -std=c++11 -w")
#Includes
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/inc/)
#External libs
set (EXT_LIBS LLLL LLLL LLLL)
#Where to find the libs above?
link_directories(${CMAKE_SOURCE_DIR}/lib/})
#Get all sources and headers
file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp)
#Finally!
add_executable(my_exec ${SOURCES})
target_link_libraries(my_exec ${EXT_LIBS})
message("Target path should be ${CMAKE_BINARY_DIR}")
Following is the cmake and build outputs and also find output which shows no exec
XXXX-MacBook-Pro:build XXXX$ rm -rf *
XXXX-MacBook-Pro:build XXXX$ cmake ..
-- The C compiler identification is AppleClang 9.0.0.9000037
-- The CXX compiler identification is AppleClang 9.0.0.9000037
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Target path should be /Users/XXXX/XXXX/XXXX/XXXX/build
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/XXXX/XXXX/XXXX/XXXX/build
XXXX-MacBook-Pro:build XXXX$ make -j34
Scanning dependencies of target my_exec
[ 9%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 18%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 27%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 36%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 45%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 54%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 72%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 72%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 81%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[ 90%] Building CXX object CMakeFiles/my_exec.dir/src/aaaa.cpp.o
[100%] Linking CXX executable my_exec
[100%] Built target my_exec
XXXX-MacBook-Pro:build XXXX$ cd ..
XXXX-MacBook-Pro:YYYY XXXX$ find . -name my*
./build/CMakeFiles/my_exec.dir

I think I have figured out the answer that took me VERY long time. The problem is the one little CMAKE_CXX_FLAG I had: "-c". It should not be there at all. CMake (for unknown reasons) passes that flag on to the "driver" c++/g++ even during the linking phase causing the underlying compiler to be invoked instead of a linker and then the compiler complains BUT ONLY AS WARNINGS that it is getting all this non-sense like *.o files and -l flags. Linking never happens as a result and so executable is never generated. And on top of this, all this drama is hidden and never shown to the user unless one does make VERBOSE=1 and actually reads the last command and then tries to use the last command by themselves with -Wall or -Werror to reveal these compiler warnings that it is getting all these linker flags.
I think this is a CMake bug but I am unsure.

Related

CMake add_executable() failing to make executable and 3rd party library failing to untar

Problem Background
I am trying to incorporate UnitTest++ into my linux-based C++17 project template. I have done this on windows pretty easily, but I am running into major issues on linux for some reason.
I used Cmake 3.21 on Windows and I am currently using CMake 3.17.5 on Linux.
I downloaded the UnitTest++ source code from the UnitTest++ Github. and proceeded to throw the tar.gz into my 3rdParty folder in my ProjectTemplate. I have had major trouble getting it to build. So I have stripped out everything except for the one 3rd party library I added and the things that folder affects. So at this point all the main() functions are very simple. I am just expecting to see executables that do nothing.
Problem Points
The main executable gets made, but the unit testing executable
(testExecutable) does not get made.
The build fully finishes with no errors even though an executable
failed to be made.
The UnitTest++ 3rd party library fails to untar with no errors
output.
I have included the build output.
Why is the testExecutable not getting made? More importantly, why is my UnitTest++ failing to untar?
Directory Structure
ProjectTemplate
+3rdParty
-CMakeLists.txt (3rd party cmake)
-unittest-cpp-2.0.0.tar.gz
+build
+src
-ClassTemplate.cpp (just a plain class file - compiles fine)
-ClassTemplate.hpp (just a plain class file - compiles fine)
-main.cpp (basic int main function)
+UnitTests
-CMakeLists.txt (unit test cmake)
-UnittestcppMain.cpp (basic int main function)
-CMakeLists.txt (root cmake)
Build Output
Output from cmake generation / configure
[main] Configuring folder: ProjectTemplate
[proc] Executing command: /usr/bin/cmake3 --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/opt/rh/devtoolset-8/root/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/opt/rh/devtoolset-8/root/usr/bin/g++ -S/path/to/ProjectTemplate -B/path/to/ProjectTemplate/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The CXX compiler identification is GNU 8.3.1
[cmake] -- Check for working CXX compiler: /opt/rh/devtoolset-8/root/usr/bin/g++
[cmake] -- Check for working CXX compiler: /opt/rh/devtoolset-8/root/usr/bin/g++ - works
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] Made it to this
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /path/to/ProjectTemplate/build
output from build
[main] Building folder: ProjectTemplate
[build] Starting build
[proc] Executing command: /usr/bin/cmake3 --build /path/to/ProjectTemplate/build --config Debug --target ExecutableName -j 18 --
[build] Scanning dependencies of target ExecutableLib
[build] [ 25%] Building CXX object CMakeFiles/ExecutableLib.dir/src/ClassTemplate.cpp.o
[build] [ 50%] Linking CXX static library libExecutableLib.a
[build] [ 50%] Built target ExecutableLib
[build] Scanning dependencies of target ExecutableName
[build] [ 75%] Building CXX object CMakeFiles/ExecutableName.dir/src/main.cpp.o
[build] [100%] Linking CXX executable ExecutableName
[build] [100%] Built target ExecutableName
[build] Build finished with exit code 0
UPDATE
Thanks to 273K a solution was pointed out. I had accidentally switched my target from "All" to "ExecutableName" in VSCode. I have included a screenshot of the problem area and what it had to be set to in order to avoid this problem for future users who might be using VSCode and stumble on this question.
This is the bottom edge of VSCode, this is where the CMake extension puts it build options.
Somehow you set --target ExecutableName, that limits the build to a single target, the main executable ExecutableName. Try to select another target, or let it unset.

Unable to generate executable file using compiler

I am trying to compile my source code using riscv64-unknown-elf-g++ compiler into a binary file but I am getting this warning and unable to generate exec file:
warning for library: libofdm.a the table of contents is empty (no object file members in the library define global symbols)
referring to this issue before:
Can't make my c++ file into a library with compiler
as suggested in the above answer the same toolchain is used to compile the object file to create the library. Even though I am getting the error. Below I am attaching the whole command line used to compile.
Last login: Thu Jul 9 12:50:56 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
(base) k:~ cd /Users/yuli/Documents/version3/cpp/
(base) k:~ ls
CMakeLists.txt src test
(base) k:~ mkdir build_riscv
(base) k:~ cd build_riscv
(base) k:~ cmake ..
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compiling RISCV
CMAKE_CXX_COMPILER: /usr/local/opt/riscv-gnu-toolchain/bin/riscv64-unknown-elf-g++
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yuli/Documents/version3/cpp/build_riscv
(base) k:~ make
Scanning dependencies of target ofdm
[ 33%] Building CXX object CMakeFiles/ofdm.dir/src/transmitter.cpp.o
[ 66%] Building CXX object CMakeFiles/ofdm.dir/src/configuration.cpp.o
[100%] Linking CXX static library libofdm.a
warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: warning for library: libofdm.a the table of contents is empty (no object file members in the library define global symbols)
[100%] Built target ofdm
(base) k:~
and FYI I am using mac machine. I am Specifying this because I saw in a post with "clang warnings macOS #3331".
clang warnings macOS #3331
CMakeLists.txt as follows:
cmake_minimum_required(VERSION 3.13)
project(ofdmchain)
set(CMAKE_CXX_COMPILER "/usr/local/opt/riscv-gnu-toolchain/bin/riscv64-unknown-elf-g++")
add_definitions(-DCOMPILES_ON_PC -Wall -Wextra)
configure_file(${CMAKE_SOURCE_DIR}/src/config.hpp.in ${CMAKE_BINARY_DIR}/config.hpp)
if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g\\+\\+")
message(STATUS "Compiling RISCV")
SET(RISCV 1)
else()
message(STATUS "Compiling X86")
SET(RISCV 0)
endif()
message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
add_library(ofdm
src/transmitter.cpp
src/configuration.cpp
src/ofdm.hpp
src/datatypes.hpp
)
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/../reference_matlab)
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/src/)
if (NOT ${RISCV})
add_executable(unit_tests
test/catch_main.cpp
test/test_sanity.cpp
test/test_utilities.cpp
test/test_transmitter.cpp
)
target_include_directories(unit_tests PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(unit_tests PUBLIC ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(unit_tests ofdm)
endif()

Distribute a Qt5 console application using CMake

I fruitlessly tried to distribute a basic Qt console application by using CMake.
Let's consider these 2 files:
main.cpp
#include <QDebug>
int main(int argc, char *argv[])
{
qDebug() << "Hello Wolrd!";
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(HelloWorld)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
qt5_use_modules(${PROJECT_NAME} Widgets)
Next I compile the main.cpp file doing:
$ cmake .
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/HelloWorld
$ make
Scanning dependencies of target HelloWorld_autogen
[ 25%] Automatic MOC for target HelloWorld
[ 25%] Built target HelloWorld_autogen
Scanning dependencies of target HelloWorld
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld_autogen/mocs_compilation.cpp.o
[ 75%] Building CXX object CMakeFiles/HelloWorld.dir/main.cpp.o
[100%] Linking CXX executable HelloWorld
[100%] Built target HelloWorld
And I get a HelloWorld binary file.
The problem comes when I try to execute the latter file on another computer which don't have Qt installed. I get this bellow error:
dyld: Library not loaded: #rpath/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /path/to/HelloWorld/./HelloWorld
Reason: image not found
./test.sh: line 4: 68737 Abort trap: 6 ./HelloWorld
What is missing to make this working as a standalone application?
Environment:
MacOs Mojave (10.14.4)
Qt 5.10.1
The easiest approach is to link Qt statically. Check out the documentation about deploying for macOS.
Be aware that Qt is licensed under the LGPL, which may have implications for static linking. Check out this FAQ for details.
You could also use bundles and frameworks, but I'm not sure how well that works with console applications.

Linking and UIC order in a CMake Qt project

Talking about a Qt 5.3.2 project which is buildt using cmake.
This is a calling order problem between UIC execution and target_link_libraries... unfortunately not in that order.
Below this text you will find
1.) a (still functional) excerpt section of my CMakeLists.txt and
2.) an excerpt of the the output of the command 'cmake .'
3.) the output of a following call to 'make' without using the
generated headers like 'ui_main.h'.
If (in the source of my library libqt.a) I require 'ui_main.h' the
make process crashes not finding the header. Looking at the
non-crashing make output shows why:
[..]
Scanning dependencies of target qt
[ 29%] Building CXX object CMakeFiles/qt.dir/home/kochmn/projects/sentinel/src/qt/form_main.cpp.o
[ 35%] Building CXX object CMakeFiles/qt.dir/qt_automoc.cpp.o
Linking CXX static library libqt.a
[..]
[ 52%] Generating ui_main.h
[..]
Make would generate libqt.a before generating the required header file.
So I experimented using code like
target_link_libraries(sentinel
${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Core_LIBRARIES})
add_library(optimization "${DIR_SRC}/optimization/linalg.cpp")
add_library(qt "${DIR_SRC}/qt/form_main.cpp")
target_link_libraries(sentinel qt optimization)
to no avail. The question: How can I motivate cmake to first run UIC generating the ui-header files and then compiling my libqt.a?
Appendix
# 2.8.11 instead of 2.8 required for automatic linking to the qtmain.lib
# library if this ever should expand to Windows.
# (http://doc.qt.io/qt-5/cmake-manual.html)
cmake_minimum_required(VERSION 2.8.11)
project(sentinel)
set( CMAKE_AUTOMOC ON )
# CMake uses uic in order to generate header files from .ui forms from designer.
set ( CMAKE AUTOUIC ON )
# Auto-generating functions write their headers into the build directory.
# Hence the build directory should be included.
set( CMAKE_INCLUDE_CURRENT_DIR ON )
#> Getting the Qt essentials. ----------------------------------------
# Widgets finds its own dependencies (QtGui and QtCore).
find_package(Qt5Widgets REQUIRED)
message ("Found Qt5Widgets Version ${Qt5Widgets_VERSION_STRING}")
# All those darling variables are explained here:
# http://doc.qt.io/qt-5/cmake-manual.html
message("Core FOUND: ${Qt5Core_FOUND}")
message("Gui FOUND: ${Qt5Gui_FOUND}")
message("Widgets FOUND: ${Qt5Widgets_FOUND}")
message("Core VERSION: ${Qt5Core_VERSION_STRING}")
message("Gui VERSION: ${Qt5Gui_VERSION_STRING}")
message("Widgets VERSION: ${Qt5Widgets_VERSION_STRING}")
message("Core INCLUDE: ${Qt5Core_INCLUDE_DIRS}")
message("Gui INCLUDE: ${Qt5Gui_INCLUDE_DIRS}")
message("Widgets INCLUDE: ${Qt5Widgets_INCLUDE_DIRS}")
message("Core LIBRARIES: ${Qt5Core_LIBRARIES}")
message("Gui LIBRARIES: ${Qt5Gui_LIBRARIES}")
message("Widgets LIBRARIES: ${Qt5Widgets_LIBRARIES}")
message("Core DEFINITIONS: ${Qt5Core_DEFINITIONS}")
message("Gui DEFINITIONS: ${Qt5Gui_DEFINITIONS}")
message("Widgets DEFINITIONS: ${Qt5Widgets_DEFINITIONS}")
message("Core COMPILE_DEFINITIONS: ${Qt5Core_COMPILE_DEFINITIONS}")
message("Gui COMPILE_DEFINITIONS: ${Qt5Gui_COMPILE_DEFINITIONS}")
message("Widgets COMPILE_DEFINITIONS: ${Qt5Widgets_COMPILE_DEFINITIONS}")
message("Core EXECUTABLE_COMPILE_FLAGS: ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
message("Gui EXECUTABLE_COMPILE_FLAGS: ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}")
message("Widgets EXECUTABLE_COMPILE_FLAGS: ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
include_directories(
${Qt5Widgets_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
#add_definitions(${Qt5Core_DEFINITIONS}) # Unnecessary. In Widgets.
#add_definitions(${Qt5Gui_DEFINITIONS}) # Unnecessary. In Widgets.
#< -------------------------------------------------------------------
set (DEBUG 1)
set (SENTINEL_NAME "Sentinel GL")
set (SENTINEL_VERSION_MAJOR "0")
set (SENTINEL_VERSION_MINOR "1")
set (SENTINEL_VERSION "${SENTINEL_VERSION_MAJOR}.${SENTINEL_VERSION_MINOR}")
## Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
# ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS} #<-- redundant.
if(CMAKE_COMPILER_IS_GNUCXX)
message("Using GnuCXX compiler.")
add_definitions("-O0 -std=c++0x -lSOIL -llapacke -lblas")
endif()
if (DEBUG MATCHES 1)
message("\nBuilding DEBUG build.")
add_definitions(-Wall)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(DIR_BASE "${PROJECT_SOURCE_DIR}/..")
set(DIR_SRC "${PROJECT_SOURCE_DIR}/../src")
set(DIR_RES "${PROJECT_SOURCE_DIR}/../resources")
set(DIR_BUILD "${PROJECT_SOURCE_DIR}/../build")
# Generated using uic FormMain.ui > ui_FormMain.h
set(qt_H
"${DIR_BUILD}/ui_main.h" "${DIR_BUILD}/ui_dialog_setup_game.h")
# Generated using the trusty QtDesigner.
set(qt_UI
"${DIR_SRC}/ui/main.ui" "${DIR_SRC}/ui/dialog_setup_game.ui")
# My own hand-written XML describing the internal resources.
set(qt_QRC "${DIR_RES}/application.qrc")
# generate rules for building source files that moc generates
QT5_WRAP_CPP(qt_H_MOC ${qt_H})
# generate rules for building header files from the ui files
QT5_WRAP_UI(qt_UI_H ${qt_UI})
# Resource Handling. QRC: "Qt Resource Collection"
QT5_ADD_RESOURCES(qt_RCCS ${qt_QRC})
# btw.: rcc generates a C program from ./resources/application.qrc
# However, this is not needed. cmake sees to that. :-)
#< -------------------------------------------------------------------
include_directories("${DIR_SRC}/include" "${PROJECT_SOURCE_DIR}")
add_executable(sentinel "${DIR_SRC}/sentinel.cpp" ${qt_H_MOC} ${qt_UI_H} ${qt_RCCS})
# Available modules are listed here: http://doc.qt.io/qt-5/qtmodules.html
# find /usr/lib/x86_64-linux-gnu/cmake -iname "*.cmake*" | less
# Note: http://stackoverflow.com/questions/20266235/cmake-error-qglwidget-no-such-file-or-directory
qt5_use_modules(sentinel Widgets Gui Core)
add_library(optimization "${DIR_SRC}/optimization/linalg.cpp")
add_library(qt "${DIR_SRC}/qt/form_main.cpp")
target_link_libraries(sentinel
${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Core_LIBRARIES}
qt optimization
)
kochmn#Ulyss:~/projects/sentinel/build$ cmake .
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- 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
Found Qt5Widgets Version 5.3.2
Core FOUND: 1
Gui FOUND: 1
Widgets FOUND: 1
Core VERSION: 5.3.2
Gui VERSION: 5.3.2
Widgets VERSION: 5.3.2
Core INCLUDE: /usr/include/x86_64-linux-gnu/qt5/;/usr/include/x86_64-linux-gnu/qt5/QtCore;/usr/lib/x86_64-linux-gnu/qt5//mkspecs/linux-g++-64
Gui INCLUDE: /usr/include/x86_64-linux-gnu/qt5/;/usr/include/x86_64-linux-gnu/qt5/QtGui;/usr/include/x86_64-linux-gnu/qt5/QtCore;/usr/lib/x86_64-linux-gnu/qt5//mkspecs/linux-g++-64
Widgets INCLUDE: /usr/include/x86_64-linux-gnu/qt5/;/usr/include/x86_64-linux-gnu/qt5/QtWidgets;/usr/include/x86_64-linux-gnu/qt5/QtGui;/usr/include/x86_64-linux-gnu/qt5/QtCore;/usr/lib/x86_64-linux-gnu/qt5//mkspecs/linux-g++-64
Core LIBRARIES: Qt5::Core
Gui LIBRARIES: Qt5::Gui
Widgets LIBRARIES: Qt5::Widgets
Core DEFINITIONS: -DQT_CORE_LIB
Gui DEFINITIONS: -DQT_GUI_LIB;-DQT_CORE_LIB
Widgets DEFINITIONS: -DQT_WIDGETS_LIB;-DQT_GUI_LIB;-DQT_CORE_LIB
Core COMPILE_DEFINITIONS: QT_CORE_LIB
Gui COMPILE_DEFINITIONS: QT_GUI_LIB;QT_CORE_LIB
Widgets COMPILE_DEFINITIONS: QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB
Core EXECUTABLE_COMPILE_FLAGS: -fPIE
Gui EXECUTABLE_COMPILE_FLAGS: -fPIE
Widgets EXECUTABLE_COMPILE_FLAGS: -fPIE
Using GnuCXX compiler.
Building DEBUG build.
Sentinel GL -- C++ Project V 0.1.
(c) Markus-Hermann Koch, mhk#markuskoch.eu, 2015/04/28-?
Primary directory is /home/kochmn/projects/sentinel/build
System is Linux
Generating configuration header: "/home/kochmn/projects/sentinel/build/../build/mhk_cmake_config.h"
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kochmn/projects/sentinel/build
kochmn#Ulyss:~/projects/sentinel/build$ make
Scanning dependencies of target optimization_automoc
[ 5%] Automatic moc for target optimization
[ 5%] Built target optimization_automoc
Scanning dependencies of target optimization
[ 11%] Building CXX object CMakeFiles/optimization.dir/home/kochmn/projects/sentinel/src/optimization/linalg.cpp.o
[ 17%] Building CXX object CMakeFiles/optimization.dir/optimization_automoc.cpp.o
Linking CXX static library liboptimization.a
[ 17%] Built target optimization
Scanning dependencies of target qt_automoc
[ 23%] Automatic moc for target qt
[ 23%] Built target qt_automoc
Scanning dependencies of target qt
[ 29%] Building CXX object CMakeFiles/qt.dir/home/kochmn/projects/sentinel/src/qt/form_main.cpp.o
[ 35%] Building CXX object CMakeFiles/qt.dir/qt_automoc.cpp.o
Linking CXX static library libqt.a
[ 35%] Built target qt
Scanning dependencies of target sentinel_automoc
[ 41%] Automatic moc for target sentinel
[ 41%] Built target sentinel_automoc
[ 47%] Generating qrc_application.cpp
[ 52%] Generating ui_main.h
[ 58%] Generating moc_ui_main.cpp
/home/kochmn/projects/sentinel/build/ui_main.h:0: Note: No relevant classes found. No output generated.
[ 64%] Generating ui_dialog_setup_game.h
[ 70%] Generating moc_ui_dialog_setup_game.cpp
/home/kochmn/projects/sentinel/build/ui_dialog_setup_game.h:0: Note: No relevant classes found. No output generated.
Scanning dependencies of target sentinel
[ 76%] Building CXX object CMakeFiles/sentinel.dir/home/kochmn/projects/sentinel/src/sentinel.cpp.o
[ 82%] Building CXX object CMakeFiles/sentinel.dir/moc_ui_main.cpp.o
[ 88%] Building CXX object CMakeFiles/sentinel.dir/moc_ui_dialog_setup_game.cpp.o
[ 94%] Building CXX object CMakeFiles/sentinel.dir/qrc_application.cpp.o
[100%] Building CXX object CMakeFiles/sentinel.dir/sentinel_automoc.cpp.o
Linking CXX executable sentinel
[100%] Built target sentinel
CMake generation order is computed from dependencies between files and targets. If your qt library depends on headers generated from .ui files, then you have to add ${qt_UI_H} in inputs of target qt:
QT5_WRAP_UI(qt_UI_H ${qt_UI})
[...]
add_library(qt "${DIR_SRC}/qt/form_main.cpp" ${qt_UI_H})
And CMake should normally execute UIC on .ui files before compiling libqt
By the way using target_link_libraries only set dependencies between targets at link time. At compile time, the normal behavior is "All source files should be found". In your case, some headers are generated, so setting these headers as input of a target ensures that the macro which generates them (QT5_WRAP_UI) will be executed before the compilation of the target.

Cmake error undefined symbols for x86_64

I am trying to compile the conv-net library in my mac osx yosemite with xcode. I even set the flags to libstdc++ still it is not linking properly.
i still get undefined symbols for architecture x86_64.
any help much appreciated.
sh-3.2# ./compile.sh
Building conv-net library
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- 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
-- Configuring done
WARNING: Target "testimg" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "testimg" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "testmnist" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "testmnist" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /var/tmp/conv-net-0.1-prealpha_buildroot
Scanning dependencies of target cvconvnet
[ 11%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvsubsamplingplane.cpp.o
[ 22%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvolutionplane.cpp.o
[ 33%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvgenericplane.cpp.o
[ 44%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvsourceplane.cpp.o
[ 55%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvrbfplane.cpp.o
[ 66%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvmaxplane.cpp.o
[ 77%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvnetparser.cpp.o
[ 88%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvfastsigmoid.cpp.o
[100%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvnet.cpp.o
/Users/prabhubalakrishnan/Desktop/conv-net/src/cvconvnet.cpp:169:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
Linking CXX static library libcvconvnet.a
[100%] Built target cvconvnet
Scanning dependencies of target testimg
Linking CXX executable testimg
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [testimg] Error 1
make[1]: *** [CMakeFiles/testimg.dir/all] Error 2
make: *** [all] Error 2
cp: testimg: No such file or directory
cp: testmnist: No such file or directory
ls: illegal option -- I
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
This is my make file
cmake_minimum_required(VERSION 3.0)
PROJECT (CvConvolutionalNet)
set (CMAKE_CXX_FLAGS " -stdlib=libstdc++")
# IF() ENDIF() statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# Specify build-type as Debug if not specified already
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF ()
# Produce verbose makefiles
# SET(CMAKE_VERBOSE_MAKEFILE ON)
# Sources for library
SET(CVCONVNET_SRCS
src/cvsubsamplingplane.cpp
src/cvconvolutionplane.cpp
src/cvgenericplane.cpp
src/cvsourceplane.cpp
src/cvrbfplane.cpp
src/cvmaxplane.cpp
src/cvconvnetparser.cpp
src/cvfastsigmoid.cpp
src/cvconvnet.cpp
)
# Sources for test files
SET(TESTIMG_SRCS tst/)
SET(TESTMNIST_SRCS tst/)
set (CV_H /usr/local/Cellar/opencv/2.4.9/include/opencv)
set (HIGHGUI_H src/include )
set (LIBCV /usr/local/Cellar/opencv/2.4.9/lib )
set (LIBHIGHGUI /usr/local/Cellar/opencv/2.4.9/lib )
# Here are common paths (in addition to default paths)
SET (INCLUDE_SEARCH_PATH
/usr/local/include /usr/include /usr/include/opencv/
/usr/include/opencv/ c:/program\ files/opencv/include
)
SET (LIBRARY_SEARCH_PATH
/usr/local/lib /usr/lib c:/program\ files/opencv/lib c:/windows/system32
)
# Find OpenCV and Expat
FIND_PATH(CV_H NAMES cv.h PATHS ${INCLUDE_SEARCH_PATH} )
FIND_PATH(HIGHGUI_H NAMES highgui.h PATHS ${INCLUDE_SEARCH_PATH} )
FIND_PATH(EXPAT_H NAMES expat.h PATHS ${INCLUDE_SEARCH_PATH} )
FIND_LIBRARY(LIBCV NAMES cv PATHS ${LIBRARY_SEARCH_PATH} )
FIND_LIBRARY(LIBHIGHGUI NAMES highgui PATHS ${LIBRARY_SEARCH_PATH} )
FIND_LIBRARY(LIBEXPAT NAMES expat PATHS ${LIBRARY_SEARCH_PATH} )
INCLUDE_DIRECTORIES(include/ ${CV_H} ${HIGHGUI_H} ${EXPAT_H})
# Here is out library
ADD_LIBRARY(cvconvnet STATIC ${CVCONVNET_SRCS})
# Here are our test programs
ADD_EXECUTABLE(testimg ${TESTIMG_SRCS})
ADD_EXECUTABLE(testmnist ${TESTMNIST_SRCS})
# Compiler options are different for Release and Debug
IF (CMAKE_BUILD_TYPE MATCHES Release)
# Highly optimized + cancel all assert()s
ADD_DEFINITIONS(-O3 -DNDEBUG)
ELSE ()
# Include debug info, profiling info, some text output
ADD_DEFINITIONS(-O -pg -g -DDEBUG)
# Set profiling for linker too
SET_TARGET_PROPERTIES(testmnist PROPERTIES LINK_FLAGS "-pg")
ENDIF ()
# We should link our test programs to libraries
TARGET_LINK_LIBRARIES(testimg cvconvnet ${LIBCV} ${LIBHIGHGUI} ${LIBEXPAT})
TARGET_LINK_LIBRARIES(testmnist cvconvnet ${LIBCV} ${LIBHIGHGUI} ${LIBEXPAT})
I fixed it by adding -c option in the compiler flags and it worked !!!!
The add_executable command takes a target name and a list of source files to be compiled. When you are creating a target for testimg you are passing it directory.
Use file(GLOB ...) command to gather all source files from directory into a list variable and pass it to add_executable call.