I am having some issues trying to link an executable which transitively uses Qt5.
I have configured my project using CMake with the option CMAKE_POSITION_INDEPENDENT_CODE = ON but still, when compiling the executable, Qt5 complains that I should use fPIC.
[ 99%] Building CXX object tools/deSimRunner/CMakeFiles/deSimRunner.dir/main.cpp.o
cd /home/jjcasmar/projects/Hybrid/Desilico/prj/Release/tools/deSimRunner && /home/jjcasmar/usr/local/bin/c++ -DBOOST_ALL_DYN_LINK -DFMT_SHARED -DHAVE_CUDA -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -D_GLIBCXX_USE_CXX11_ABI=1 -I/home/jjcasmar/projects/Hybrid/Desilico/src/deCore -I/home/jjcasmar/projects/Hybrid/Desilico/src/deCore/.. -I/home/jjcasmar/projects/Hybrid/Desilico/src/deGeom/.. -I/opt/cuda/include -I/home/jjcasmar/projects/Hybrid/Desilico/src/deSim/.. -isystem /home/jjcasmar/.conan/data/eigen/3.3.7/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3 -isystem /home/jjcasmar/.conan/data/rapidjson/1.1.0/bincrafters/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /home/jjcasmar/.conan/data/boost/1.71.0/conan/stable/package/393cfc058d5be864014f06fc0bb0e29c6845d9e9/include -isystem /home/jjcasmar/.conan/data/zlib/1.2.11/conan/stable/package/1d877a3df840030e6a8abb74c5ffb9088d08b47a/include -isystem /home/jjcasmar/.conan/data/bzip2/1.0.8/conan/stable/package/a5875aed3fc7ae8dd0488f7e5e99acbc480d721d/include -isystem /usr/include/qt -isystem /usr/include/qt/QtCore -isystem /usr/lib/qt/mkspecs/linux-g++ -isystem /home/jjcasmar/.conan/data/spdlog/1.4.2/bincrafters/stable/package/f31849fd5982a882fc905666fe297f0c231b10af/include -isystem /home/jjcasmar/.conan/data/fmt/6.0.0/bincrafters/stable/package/ca4b767114c8e107f72671a3380d9917e2b9adff/include -isystem /home/jjcasmar/.conan/data/OpenMesh/7.1/desilico/stable/package/b80d46004713aa37d6a90b42e2a326a056a237b5/include -isystem /home/jjcasmar/.conan/data/nanoflann/1.3.0/desilico/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /home/jjcasmar/usr/local/include -isystem /home/jjcasmar/.conan/data/cereal/1.2.2/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /home/jjcasmar/.conan/data/glm/0.9.9.5/g-truc/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /usr/include/qt/QtGui -isystem /home/jjcasmar/.conan/data/range-v3/0.9.1/ericniebler/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -fopenmp -O3 -DNDEBUG -fPIE -DNON_COMMERCIAL_LICENSE -std=gnu++14 -o CMakeFiles/deSimRunner.dir/main.cpp.o -c /home/jjcasmar/projects/Hybrid/Desilico/tools/deSimRunner/main.cpp
In file included from /usr/include/qt/QtCore/qjsonvalue.h:43,
from /usr/include/qt/QtCore/qjsondocument.h:43,
from /usr/include/qt/QtCore/QJsonDocument:1,
from /home/jjcasmar/projects/Hybrid/Desilico/tools/deSimRunner/main.cpp:23:
/usr/include/qt/QtCore/qglobal.h:1204:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
I have these two options enabled in my main CMakeLists.txt file
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(BUILD_SHARED_LIBS ON)
How should I correctly add the fPIC option for my final executable?
Your error states:
"You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
However, your compilation flags only contain fPIE, not fPIC:
/usr/local/bin/c++ -DBOOST_ALL_DYN_LINK ...
...
-fopenmp -O3 -DNDEBUG -fPIE -DNON_COMMERCIAL_LICENSE -std=gnu++14 -o CMakeFiles/deSimRunner.dir/main.cpp.o -c /home/jjcasmar/projects/Hybrid/Desilico/tools/deSimRunner/main.cpp
You were correct to try using CMAKE_POSITION_INDEPENDENT_CODE, but this variable may not set the flags you expect. The fairly undocumented behavior for this variable is this:
If the target is a library, the flag -fPIC is added by CMake to the compilation and linker steps.
If the target is an executable, the flag -fPIE is added by CMake to the compilation and linker steps.
Thus, you will have to add the -fPIC flag for your executable somewhat manually, with something like this:
add_executable(deSimRunner ... )
target_compile_options(deSimRunner PRIVATE -fPIC)
Related
this is my first Stack Overflow question so please do not mind the terminology.
I try to build a package using devtools::build using a conda environment from my WSL:
devtools::build('pkg')
However, i get the following error
Error: Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
When i diagnose the problem i get the following
> pkgbuild::check_build_tools(debug = TRUE)
Trying to compile a simple C file
Running /home/name/miniconda3/envs/pipeline_env/lib/R/bin/R CMD SHLIB foo.c
x86_64-conda-linux-gnu-cc -I"/home/name/miniconda3/envs/pipeline_env/lib/R/include" -DNDEBUG -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/name/miniconda3/envs/pipeline_env/include -I/home/name/miniconda3/envs/pipeline_env/include -Wl,-rpath-link,/home/name/miniconda3/envs/pipeline_env/lib -fpic -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/name/miniconda3/envs/pipeline_env/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base-split_1648745733215/work=/usr/local/src/conda/r-base-4.1.3 -fdebug-prefix-map=/home/name/miniconda3/envs/pipeline_env=/usr/local/src/conda-prefix -c foo.c -o foo.o
/bin/sh: 1: x86_64-conda-linux-gnu-cc: not found
make: *** [/home/name/miniconda3/envs/pipeline_env/lib/R/etc/Makeconf:170: foo.o] Error 127
Getting the following error in my library when trying to compile a library that is linking against Qt.
/opt/local/libexec/qt5/lib/QtCore.framework/QtCore:1:1: error: source file is not valid UTF-8
File.cxx is
#include <QtCore>
int main(){
return 0;
}
Using mac ports
Unsure if this is some weird mac problem or?
/opt/local/bin/clang++-mp-11 -DQT_CORE_LIB -D_LINUX_OS_ -D_XOPEN_SOURCE=600 -I/opt/local/libexec/qt5/include -isystem /opt/local/libexec/qt5/lib/QtCore.framework -isystem /opt/local/libexec/qt5/lib/QtCore.framework/Headers -isystem /opt/local/libexec/qt5/./mkspecs/macx-clang -g -std=c99 -pedantic -Wall -Wstrict-prototypes -Wwrite-strings -Wpointer-arith -Wcast-align -Werror -fPIC -std=gnu++11 -MD -MT fie.cxx.obj -MF file.cxx.obj.d -o file.cxx.obj -c file.cxx
Ive gotten similar results using xcode's compiler
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/CC
I have a R script that tries to install many packages (omitted all but showing just one):
install.packages("zoo")
Then I run
Rscript my_r.r
Then, I noticed it will try to compile some C code:
gcc -m64 -std=gnu99 -I"/usr/include/R" -DNDEBUG -I../inst/include -I"/latest/rsg_comm/r_packages/zoo/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c any.c -o any.o
Is there a way to ask all packages to be compiled locally with -O3 and -mtune=native?
I noticed that there is a similar post that suggests using ~/R/.Makevars. But it seems like
it will override all compiler flags instead of just those 2 I specify. Is there a way to specify?
I have to download the source package of each source, which is not as convenient as just using install.packages("package_name"), which will figure the latest version, and go through a mirror, etc. Or there is a convenient way?
You can edit your .R/Makevars file and append the desired flags using the += operator, e.g.
CFLAGS+= -O3 -Wall -mtune=native -march=native
The latter flag is used if there is a conflict, as you said in your comment below. In terms of compiling from source, you can do this via install.packages(), e.g.
install.packages("package_name", type = "source")
For example, lets take a default QT widget application that we get. So instead of using QT Creator if we want to build using the terminal then what is the way to do that?
Basically we want to produce the build for the project which actually also contains the dmg file.
Compile output when done using QT Creator shown is below when no change is done :
14:37:04: Running steps for project QTDefaultProj...
14:37:04: Configuration unchanged, skipping qmake step.
14:37:04: Starting: "/usr/bin/make"
make: Nothing to be done for `first'.
14:37:05: The process "/usr/bin/make" exited normally.
14:37:05: Elapsed time: 00:00.
Compile Output after changing the directory :
15:31:50: Running steps for project QTDefaultProj...
15:31:50: Starting: "/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/bin/qmake" /Users/arqam/Desktop/Junk/QTDefaultProj/QTDefaultProj.pro -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug
Info: creating stash file /Users/arqam/Desktop/Junk/build-QTDefaultProj-Desktop_Qt_5_10_0_clang_64bit-Debug-2/.qmake.stash
15:31:50: The process "/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/bin/qmake" exited normally.
15:31:50: Starting: "/usr/bin/make" qmake_all
make: Nothing to be done for `qmake_all'.
15:31:51: The process "/usr/bin/make" exited normally.
15:31:51: Starting: "/usr/bin/make"
/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/bin/uic ../QTDefaultProj/mainwindow.ui -o ui_mainwindow.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../QTDefaultProj -I. -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtWidgets.framework/Headers -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtGui.framework/Headers -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../ImageToCartoon/QT/5.10.0/clang_64/mkspecs/macx-clang -F/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib -o main.o ../QTDefaultProj/main.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../QTDefaultProj -I. -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtWidgets.framework/Headers -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtGui.framework/Headers -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../ImageToCartoon/QT/5.10.0/clang_64/mkspecs/macx-clang -F/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib -o mainwindow.o ../QTDefaultProj/mainwindow.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -pipe -stdlib=libc++ -g -std=gnu++11 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wall -W -dM -E -o moc_predefs.h ../../ImageToCartoon/QT/5.10.0/clang_64/mkspecs/features/data/dummy.cpp
/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/bin/moc -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB --include ./moc_predefs.h -I/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/mkspecs/macx-clang -I/Users/arqam/Desktop/Junk/QTDefaultProj -I/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib/QtWidgets.framework/Headers -I/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib/QtGui.framework/Headers -I/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/8.1.0/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include -F/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib ../QTDefaultProj/mainwindow.h -o moc_mainwindow.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../QTDefaultProj -I. -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtWidgets.framework/Headers -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtGui.framework/Headers -I../../ImageToCartoon/QT/5.10.0/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../ImageToCartoon/QT/5.10.0/clang_64/mkspecs/macx-clang -F/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib -o moc_mainwindow.o moc_mainwindow.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wl,-rpath,#executable_path/Frameworks -Wl,-rpath,/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib -o QTDefaultProj.app/Contents/MacOS/QTDefaultProj main.o mainwindow.o moc_mainwindow.o -F/Users/arqam/Desktop/ImageToCartoon/QT/5.10.0/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
15:31:55: The process "/usr/bin/make" exited normally.
15:31:55: Elapsed time: 00:05.
With help from m7913d I am finally able to build the QT project from terminal without using QT Creator.
So steps are :
Create an empty folder name it as build-debug for example.
Inside your build-debug folder run the following command :
pathToQTDirectory/QT/5.10.0/clang_64/bin/qmake pathToQTProjectFolder/MyProject/
/usr/bin/make qmake_all
/usr/bin/make
If the above doesn't work then try seeing in the QT Creator compiler output the steps involved when you specify a new directory as the build directory.
I try to compile my app, QNX and Qt is all set.
in line 3.
C:/QNX650/target/qnx6armle-v7 is in the QNX_TARGET env var, and C:/QNX650/host/win32/x86 is QNX_HOST env var. this is strange they combine together.
Qtcreator, debug mode.this is the only output
qcc -Vgcc_ntoarmv7le -c -Wno-psabi -lang-c++ -g -Wall -W -D_REENTRANT -fPIE -DQT_NO_CLIPBOARD -DHMI_PLUGIN_DEBUG -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/mkspecs/qnx-armv7le-qcc -I../MQueue_Demo -I../MQueue_Demo/qtquick2applicationviewer -I../MQueue_Demo/depends/MQueue/include -I../MQueue_Demo/depends/MQueue/include/native -I../MQueue_Demo/depends/hmi_interfaces -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include/QtQuick -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include/QtQml -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include/QtNetwork -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include/QtGui -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include/QtGui/5.0.2 -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include/QtGui/5.0.2/QtGui -I../../../../QtQNX/Qt5.0.2/5.0.2/qnx_armv7le/include/QtCore -I. -IC:\QNX650\target\qnx6\armle-v7/target/qnx6/usr/include -IC:\QNX650\target\qnx6\armle-v7/target/qnx6/usr/include/freetype2 -I. -o main.obj ../MQueue_Demo/main.cpp
cc: unknown target 'gcc_ntoarmv7le+debug'
cc: no targets defined in C:/QNX650/target/qnx6/armle-v7/host/win32/x86/etc/qcc!
make: *** [main.obj] Error 1
09:46:25: The process "C:\QNX650\host\win32\x86\usr\bin\make.exe" exited with code 2.