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.
Related
When using this CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(project_c)
set(CMAKE_CXX_STANDARD 11)
set(project_name project_c)
find_package(BISON)
find_package(FLEX)
BISON_TARGET(parser parser.y ${CMAKE_SOURCE_DIR}/parser.cpp)
FLEX_TARGET(lexer lexer.l ${CMAKE_SOURCE_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(lexer parser)
add_executable(${project_name} ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS})
target_include_directories(${project_name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${project_name} ${FLEX_LIBRARIES})
CMake complains about
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
FL_LIBRARY (ADVANCED)
linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c
I've tried to copy the winflex folder inside the project folder but that won't help anyway. This proposed solution isn't working.
This is the complete CMake log
"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\asant\workspace\CLionProjects\project_c
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - 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: C:/Qt/Tools/mingw810_64/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found BISON: C:/Program Files (x86)/win_flex_bison-2.5.23/win_bison.exe (found version "3.7.1")
-- Found FLEX: C:/Program Files (x86)/win_flex_bison-2.5.23/win_flex.exe (found version "2.6.4")
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
FL_LIBRARY (ADVANCED)
linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
[Failed to reload]
I've managed to build a WxWidgets based on CMake on Ubuntu 19.10, but failed on Windows 10, saying that it cannot find WxWidgets, though I've built it successfully (static, release and with unicode support).
WxWidgets path is C:\wxWidgets-3.1.3 and the build directory is C:\wxWidgets-3.1.3\msw-release.
The makefile is
cmake_minimum_required(VERSION 3.0)
project(ChessPgnReviser VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
ADD_DEFINITIONS(-Wall -Wno-sign-compare -O2)
set(SRCS
src/main.cpp
)
set (HEADERS
)
message( "--Root--" ${wxWidgets_ROOT_DIR} )
message( "--Lib dir--" ${wxWidgets_LIB_DIR} )
add_executable(ChessPgnReviser ${SRCS} ${HEADERS})
find_package(wxWidgets COMPONENTS net gl core base)
if(wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})
target_link_libraries(ChessPgnReviser ${wxWidgets_LIBRARIES})
else()
message(FATAL_ERROR "Failed to find WxWidgets library")
endif()
I'm using Msys 64 bit in order to compile the project. At the bottom of its subfolder etc/profile, I've added
PATH=$PATH:/c/dev/cmake/bin
wxWidgets_ROOT_DIR=/c/wxWidgets-3.1.3
wxWidgets_LIBRARIES=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_LIB_DIR=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_INCLUDE_DIRS=$wxWidgets_ROOT_DIR/include
So I've tried
$ mkdir build && cd build
$ cmake .. -G "MinGW Makefiles"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - 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: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--
--Lib dir--
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
Also, thanks to #squareskittles, I also tried:
$ cmake .. -G "MinGW Makefiles" -DwxWidgets_ROOT_DIR="C:\wxWidgets-3.1.3" -DwxWidgets_LIB_DIR="C:\wxWidgets-3.1.3\msw-release\lib"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - 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: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--C:\wxWidgets-3.1.3
--Lib dir--C:\wxWidgets-3.1.3\msw-release\lib
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
You can find the content of the msw-release folder : there.
Also:
$ ls /c/wxWidgets-3.1.3/msw-release/lib/
libwx_baseu_net-3.1.a libwx_baseu-3.1.a libwx_mswu_aui-3.1.a libwx_mswu_gl-3.1.a libwx_mswu_media-3.1.a libwx_mswu_qa-3.1.a libwx_mswu_richtext-3.1.a libwx_mswu_webview-3.1.a libwxregexu-3.1.a wx
libwx_baseu_xml-3.1.a libwx_mswu_adv-3.1.a libwx_mswu_core-3.1.a libwx_mswu_html-3.1.a libwx_mswu_propgrid-3.1.a libwx_mswu_ribbon-3.1.a libwx_mswu_stc-3.1.a libwx_mswu_xrc-3.1.a libwxscintilla-3.1.a
So did I forget something ?
To properly detect wxWidgets you need wx-config.
A Windows version of wx-config exists and can be downloaded from: https://github.com/kowey/wx-config-win
To make wx-config know where your wxWidgets is, you need set the following environment variables:
WXWIN (in your case to C:/wxWidgets-3.1.3)
WXCFG (in your case to something like msw/gcc_mswu).
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()
So, i set up my Cloin/SFML project like this : configure SFML for clion (windows)
and added the SFML_ROOT variable, and then it works exactly once, and every time i try too run it after the first, i get this error(gam is the project name, it is set correctly in the CMakeLists.txt file):
mingw32-make.exe: *** No rule to make target 'gam'. Stop.
How do i get it to work more than once?(It might be something as stupid as me clicking the wrong button to run this thing. I´m new to Clion and cmake)
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(gam)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(gam ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(gam ${SFML_LIBRARIES})
endif()
output of CMake when project is first initialized:
"C:\Program Files\JetBrains\CLion 2018.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\programierzeug\c++\test
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe
-- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe -- 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: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe -- 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: D:/programierzeug/c++/test/cmake-build-debug
[Finished]
output of CMake when reloading project:
"C:\Program Files\JetBrains\CLion 2018.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\programierzeug\c++\test
-- Configuring done
-- Generating done
-- Build files have been written to: D:/programierzeug/c++/test/cmake-build-debug
[Finished]
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.