MinGW+cmake on Windows 10 produce error: '__MINGW_EXTENSION' does not name a type - cmake

I have spent long time developing C/C++ under Linux, now I'm trying to port/compile my project under windows where I have no experinece. I want to keep the workflow as close to Linux as possible so I go with g++/MinGW and cmake.
When I do standard approach
cd Build
cmake .. -G "MinGW Makefiles"
make
I got tons of following errors:
PS D:\git\SimpleSimulationEngine\cpp\Build> make VERBOSE=1
"C:\Program Files\CMake\bin\cmake.exe" -SD:\git\SimpleSimulationEngine\cpp -BD:\git\SimpleSimulationEngine\cpp\Build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start D:\git\SimpleSimulationEngine\cpp\Build\CMakeFiles D:\git\SimpleSimulationEngine\cpp\Build\\CMakeFiles\progress.marks
C:/MinGW/bin/make -f CMakeFiles\Makefile2 all
make[1]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
C:/MinGW/bin/make -f common\algorithms\CMakeFiles\algorithms.dir\build.make common/algorithms/CMakeFiles/algorithms.dir/depend
make[2]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" D:\git\SimpleSimulationEngine\cpp D:\git\SimpleSimulationEngine\cpp\common\algorithms D:\git\SimpleSimulationEngine\cpp\Build D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms\CMakeFiles\algorithms.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'D:/git/SimpleSimulationEngine/cpp/Build'
C:/MinGW/bin/make -f common\algorithms\CMakeFiles\algorithms.dir\build.make common/algorithms/CMakeFiles/algorithms.dir/build
make[2]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
[ 1%] Building CXX object common/algorithms/CMakeFiles/algorithms.dir/main.cpp.obj
cd /d D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms && C:\MinGW\bin\g++.exe #CMakeFiles/algorithms.dir/includes_CXX.rsp -Wall -std=c++17 -g -Og -fPIC -fno-strict-aliasing -Wno-maybe-uninitialized -Wno-char-subscripts -Wno-write-strings -Wno-format -Wno-parentheses -Wno-unused-but-set-variable -Wno-narrowing -Wno-unused-result -Wno-sign-compare -Wno-strict-aliasing -Wno-unused-variable -Wno-unused-value -Wno-comment -Wno-misleading-indentation -Werror=return-type -o CMakeFiles\algorithms.dir\main.cpp.obj -c D:\git\SimpleSimulationEngine\cpp\common\algorithms\main.cpp
In file included from c:\mingw\x86_64-w64-mingw32\include\stdlib.h:9:0,
from c:\mingw\include\c++\6.1.0\cstdlib:75,
from D:/git/SimpleSimulationEngine/cpp/common/utils/testUtils.h:6,
from D:\git\SimpleSimulationEngine\cpp\common\algorithms\main.cpp:2:
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:35:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef unsigned __int64 size_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:45:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef __int64 ssize_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:52:9: error: 'size_t' does not name a type
typedef size_t rsize_t;
^~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:62:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef __int64 intptr_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:75:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
I'm not sure my MinGW environment and libraries are setup properly, since I tried some older minGW version before, than I reinstalled it. Also I have installed MSYS2 in an atempt to install GLEW. But I do not use MSYS2 now, I use some stand alone instalation of MinGW and cmake.
There is nothing special in my CMakeLists.txt
cmake_minimum_required ( VERSION 2.8 )
project ( SimpleSimulationEngine )
set(default_build_type Release)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17" )
SET( IGNORE_WARRNING_FLAGS "-Wno-maybe-uninitialized -Wno-char-subscripts -Wno-write-strings -Wno-format -Wno-parentheses -Wno-unused-but-set-variable -Wno-narrowing -Wno-unused-result -Wno-sign-compare -Wno-strict-aliasing -Wno-unused-variable -Wno-unused-value -Wno-comment -Wno-misleading-indentation " )
SET( WARRNING_TO_ERROR "-Werror=return-type")
SET( AXULIARY_COMPILE_FLAGS "-g -Og -fPIC -fno-strict-aliasing ")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AXULIARY_COMPILE_FLAGS} ${IGNORE_WARRNING_FLAGS}
message ( "CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} )
When I check my environment variables/path there does not seem to be anything fishy (like two versions of MinGW)

Related

CMake Assembler error "No such instruction"

I am moving an already existing project from Atmel Studio 7.0 with arm-gnu toolchain to CMake with MinGW generator.
I have configured the CXX and C compiler flags as follows:
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT="\"Feather M0\"" -DUSB_MANUFACTURER="\"Adafruit\"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls -Wall -Wa -mcpu=cortex-m0plus -std=gnu99")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-x c D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT="\"Feather M0\"" -DUSB_MANUFACTURER="\"Adafruit\"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -mlong-calls -Wall -mcpu=cortex-m0plus -Wa-c -std=gnu99")
Here is the exact verbose command that generates the error.
:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\CMakeFiles C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\\CMakeFiles\progress.marks
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f CMakeFiles\Makefile2 all
make[1]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f Library\CMakeFiles\Library.dir\build.make Library/CMakeFiles/Library.dir/depend
make[2]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\Library C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library\CMakeFiles\Library.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f Library\CMakeFiles\Library.dir\build.make Library/CMakeFiles/Library.dir/build
make[2]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
[ 1%] Building CXX object Library/CMakeFiles/Library.dir/src/Adafruit_SleepyDog/utility/WatchdogSAMD.cpp.obj
cd /d C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library && C:\MinGW\bin\g++.exe #CMakeFiles/Library.dir/includes_CXX.rsp -march=native -mno-avx -D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT=;"Feather;M0"" -DUSB_MANUFACTURER=""Adafruit"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls -Wall -Wa -mcpu=cortex-m0plus -std=gnu99" -o CMakeFiles\Library.dir\src\Adafruit_SleepyDog\utility\WatchdogSAMD.cpp.obj -c C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\Library\src\Adafruit_SleepyDog\utility\WatchdogSAMD.cpp
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s: Assembler messages:
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:47: Error: number of operands mismatch for `ds'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:53: Error: no such instruction: `isb 0xF'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:527: Error: number of operands mismatch for `ds'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:533: Error: no such instruction: `wfi'
Any idea what might be the reason - in terms of toolchain - assembler ? Is there any way to specify assembler flags in CMake?
You're using MinGW GCC, which essentially targets Windows.
So I don't believe you can target other platforms..
What you need is a GCC compiler that runs on windows that supports the target platform(s) you need.
For Atmel ARM you can try something like this: http://winavr.sourceforge.net/ (though maybe something more recent may exist).

Compile order with TARGET_LINK_LIBRARIES in three CMakeLists.txt

I have a problem with CMake: A static library and an executable are made but the build process is out of order. Thus, the library does not exist when the executable tries to link. I have read similar questions but did not find a solution. My project uses one root-CMakelists.txt that includes the other two:
Root: dev/CMakeLists.txt:
# Library project
include(${CMAKE_CURRENT_SOURCE_DIR}/src_lib/CMakeLists.txt)
# Client project
include(${CMAKE_CURRENT_SOURCE_DIR}/src_client/CMakeLists.txt)
Library: dev/src_lib/CMakeLists.txt
add_library(wof_static STATIC ${LIB_SRC})
TARGET_LINK_LIBRARIES(wof_static ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/lex/libs/amd64/libLexActivator.a pthread libnss3.so /usr/lib/x86_64-linux-gnu/libssl3.so /usr/lib/x86_64-linux-gnu/libnspr4.so )
Executable: dev/src_client/CMakeLists.txt
add_executable(wof ${CLIENT_SRC})
TARGET_LINK_LIBRARIES( wof
${CMAKE_CURRENT_SOURCE_DIR}/build/libwof_static.a
${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
gmp
pthread
libnss3.so
/usr/lib/x86_64-linux-gnu/libssl3.so
/usr/lib/x86_64-linux-gnu/libnspr4.so
)
The above TARGET_LINK_LIBRARIES command uses the filename libwof_static.a, and thus, the build is out of order (i.e., it works only when I call make twice). Thus, I need to let CMake know that the executable depends on the library-target wof_static, right? I tried to do so:
Executable: dev/src_client/CMakeLists.txt (variant)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/build/ ${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/)
add_executable(wof ${CLIENT_SRC})
TARGET_LINK_LIBRARIES( wof
wof_static
${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
gmp
pthread
libnss3.so
/usr/lib/x86_64-linux-gnu/libssl3.so
/usr/lib/x86_64-linux-gnu/libnspr4.so
)
The intention of the above is to let CMake know the target name wof_static. That seems to work because the compilation of the executable wof starts when the library is ready. But I assumed that CMake would know and use the output file libwof_static.a of the target wof_static. This does not seem to be true. The error I get is:
[ 94%] Linking CXX static library libwof_static.a
/usr/local/bin/cmake -P CMakeFiles/wof_static.dir/cmake_clean_target.cmake
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/wof_static.dir/link.txt --verbose=1
/usr/bin/ar qc libwof_static.a CMakeFiles/wof_static.dir/src_lib/AngleEntry.cpp.o CMakeFiles/wof_static.dir/src_lib/CEdge.cpp.o CMakeFiles/wof_static.dir/src_lib/CMesh.cpp.o CMakeFiles/wof_static.dir/src_lib/CPatch.cpp.o CMakeFiles/wof_static.dir/src_lib/CTriangle.cpp.o CMakeFiles/wof_static.dir/src_lib/Calc.cpp.o CMakeFiles/wof_static.dir/src_lib/Casx.cpp.o CMakeFiles/wof_static.dir/src_lib/Chain.cpp.o CMakeFiles/wof_static.dir/src_lib/ChainMgr.cpp.o CMakeFiles/wof_static.dir/src_lib/Cloud.cpp.o CMakeFiles/wof_static.dir/src_lib/CloudMgr.cpp.o CMakeFiles/wof_static.dir/src_lib/Hal.cpp.o CMakeFiles/wof_static.dir/src_lib/Histogram.cpp.o CMakeFiles/wof_static.dir/src_lib/HoleFiller.cpp.o CMakeFiles/wof_static.dir/src_lib/HoleToCCD.cpp.o CMakeFiles/wof_static.dir/src_lib/Inspector.cpp.o CMakeFiles/wof_static.dir/src_lib/Iso.cpp.o CMakeFiles/wof_static.dir/src_lib/IsoStore.cpp.o CMakeFiles/wof_static.dir/src_lib/LexSample.cpp.o CMakeFiles/wof_static.dir/src_lib/Loop.cpp.o CMakeFiles/wof_static.dir/src_lib/Performance.cpp.o CMakeFiles/wof_static.dir/src_lib/Pixel.cpp.o CMakeFiles/wof_static.dir/src_lib/Plane.cpp.o CMakeFiles/wof_static.dir/src_lib/Posix.cpp.o CMakeFiles/wof_static.dir/src_lib/Rotx.cpp.o CMakeFiles/wof_static.dir/src_lib/Segment3.cpp.o CMakeFiles/wof_static.dir/src_lib/Smooth.cpp.o CMakeFiles/wof_static.dir/src_lib/Surve.cpp.o CMakeFiles/wof_static.dir/src_lib/Top.cpp.o CMakeFiles/wof_static.dir/src_lib/TopMelt.cpp.o CMakeFiles/wof_static.dir/src_lib/Vector3.cpp.o CMakeFiles/wof_static.dir/src_lib/Visualizer3.cpp.o CMakeFiles/wof_static.dir/src_lib/Voro.cpp.o CMakeFiles/wof_static.dir/src_lib/Wof.cpp.o CMakeFiles/wof_static.dir/src_lib/WofMesh.cpp.o CMakeFiles/wof_static.dir/src_lib/api.cpp.o CMakeFiles/wof_static.dir/src_lib/api_io.cpp.o CMakeFiles/wof_static.dir/src_lib/devStuff.cpp.o CMakeFiles/wof_static.dir/src_lib/freeFunctions.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_locate3/Node.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_locate3/RTree.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_octree/OctNode.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_octree/Octree.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_tools/GSS_HC2.cpp.o CMakeFiles/wof_static.dir/src_lib/geom_tools/GSS_HC3.cpp.o CMakeFiles/wof_static.dir/src_lib/testDataGenerators.cpp.o CMakeFiles/wof_static.dir/src_lib/tinyply.cpp.o CMakeFiles/wof_static.dir/src_lib/tools.cpp.o
/usr/bin/ranlib libwof_static.a
make[2]: Leaving directory '/home/geom/repoWOF/dev/build'
[ 94%] Built target wof_static
make -f CMakeFiles/wof.dir/build.make CMakeFiles/wof.dir/depend
make[2]: Entering directory '/home/geom/repoWOF/dev/build'
cd /home/geom/repoWOF/dev/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/geom/repoWOF/dev /home/geom/repoWOF/dev /home/geom/repoWOF/dev/build /home/geom/repoWOF/dev/build /home/geom/repoWOF/dev/build/CMakeFiles/wof.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/geom/repoWOF/dev/build'
make -f CMakeFiles/wof.dir/build.make CMakeFiles/wof.dir/build
make[2]: Entering directory '/home/geom/repoWOF/dev/build'
[ 96%] Building CXX object CMakeFiles/wof.dir/src_client/Params.cpp.o
[ 98%] Building CXX object CMakeFiles/wof.dir/src_client/main.cpp.o
make[2]: *** No rule to make target '../3rdParty/lex/libs/amd64/libLexActivator.a', needed by 'wof'. Stop.
make[2]: *** Waiting for unfinished jobs....
/usr/bin/c++ -I/home/geom/repoWOF/dev/include -O3 -DNDEBUG -std=c++11 -fstrict-aliasing -Wno-unused-local-typedefs -Wno-long-long -O3 -Wextra -Wunused -Wall -pedantic-errors -frounding-math -funroll-loops -Wl,-s -o CMakeFiles/wof.dir/src_client/Params.cpp.o -c /home/geom/repoWOF/dev/src_client/Params.cpp
/usr/bin/c++ -I/home/geom/repoWOF/dev/include -O3 -DNDEBUG -std=c++11 -fstrict-aliasing -Wno-unused-local-typedefs -Wno-long-long -O3 -Wextra -Wunused -Wall -pedantic-errors -frounding-math -funroll-loops -Wl,-s -o CMakeFiles/wof.dir/src_client/main.cpp.o -c /home/geom/repoWOF/dev/src_client/main.cpp
make[2]: Leaving directory '/home/geom/repoWOF/dev/build'
CMakeFiles/Makefile2:112: recipe for target 'CMakeFiles/wof.dir/all' failed
make[1]: *** [CMakeFiles/wof.dir/all] Error 2
make[1]: Leaving directory '/home/geom/repoWOF/dev/build'
Makefile:86: recipe for target 'all' failed
make: *** [all] Error 2
In your file dev/src_client/CMakeLists.txt, this line:
${CMAKE_CURRENT_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
evaluates to the path:
dev/src_client/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
I don't think that is what you intend, as this path is different from the path you use in the dev/src_lib/CMakeLists.txt file.
Instead of CMAKE_CURRENT_SOURCE_DIR, use the CMake variable that points to the root source directory: CMAKE_SOURCE_DIR. Try something like this:
TARGET_LINK_LIBRARIES( wof
wof_static
${CMAKE_SOURCE_DIR}/src_lib/3rdParty/lex/libs/amd64/libLexActivator.a
gmp
pthread
libnss3.so
/usr/lib/x86_64-linux-gnu/libssl3.so
/usr/lib/x86_64-linux-gnu/libnspr4.so
)

CMake with IBMs mpixlf2008

I am trying to compile a Fortran program using CMake on an IBM BlueGene machine. This is my source:
> tree
.
├── CMakeLists.txt
└── src
└── test1.f90
where test1.f90 simply is:
program main
use mpi
integer :: me, ierr
call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, me, ierr)
write (*,"(I4,A)") me, ": hello"
call MPI_Finalize(ierr)
end program main
I would like to create a static executable. Therefore I created this CMakeLists.txt:
cmake_minimum_required(VERSION 2.5)
project(STB)
file(GLOB_RECURSE sources src/*.f90)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(BUILD_SHARED_LIBRARIES OFF)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
add_executable(test.x ${sources})
enable_language(Fortran)
set(CMAKE_Fortran_COMPILER_ID "IBM")
if(CMAKE_Fortran_COMPILER_ID MATCHES "IBM")
MESSAGE(STATUS "IBM")
set(CMAKE_Fortran_COMPILER mpixlf2008)
set(dialect "-O2 -qarch=qp -qtune=qp -ufmt_littleendian={23}")
set(debug "-C")
endif()
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
MESSAGE( STATUS "cmake_module_path: " ${CMAKE_MODULE_PATH})
this results in:
make VERBOSE=1
/usr/bin/cmake -H/work/jias12/jias1217/test -B/work/jias12/jias1217/test --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /work/jias12/jias1217/test/CMakeFiles /work/jias12/jias1217/test/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/work/jias12/jias1217/test'
make -f CMakeFiles/test.x.dir/build.make CMakeFiles/test.x.dir/depend
make[2]: Entering directory `/work/jias12/jias1217/test'
cd /work/jias12/jias1217/test && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /work/jias12/jias1217/test /work/jias12/jias1217/test /work/jias12/jias1217/test /work/jias12/jias1217/test /work/jias12/jias1217/test/CMakeFiles/test.x.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/work/jias12/jias1217/test'
make -f CMakeFiles/test.x.dir/build.make CMakeFiles/test.x.dir/requires
make[2]: Entering directory `/work/jias12/jias1217/test'
make[2]: Nothing to be done for `CMakeFiles/test.x.dir/requires'.
make[2]: Leaving directory `/work/jias12/jias1217/test'
make -f CMakeFiles/test.x.dir/build.make CMakeFiles/test.x.dir/build
make[2]: Entering directory `/work/jias12/jias1217/test'
/usr/bin/cmake -E cmake_progress_report /work/jias12/jias1217/test/CMakeFiles 1
[100%] Building Fortran object CMakeFiles/test.x.dir/src/test1.o
mpixlf2008 -O2 -qarch=qp -qtune=qp -ufmt_littleendian={23} -c /work/jias12/jias1217/test/src/test1.f90 -o CMakeFiles/test.x.dir/src/test1.o
** main === End of Compilation 1 ===
1501-510 Compilation successful for file test1.f90.
Linking Fortran executable test.x
/usr/bin/cmake -E cmake_link_script CMakeFiles/test.x.dir/link.txt --verbose=1
mpixlf2008 -static -O2 -qarch=qp -qtune=qp -ufmt_littleendian={23} CMakeFiles/test.x.dir/src/test1.o -o test.x -rdynamic
/opt/ibmcmp/xlf/bg/14.1/bin/.orig/bgxlf2008: 1501-210 (S) command option ynamic contains an incorrect subargument
make[2]: *** [test.x] Error 40
make[2]: Leaving directory `/work/jias12/jias1217/test'
make[1]: *** [CMakeFiles/test.x.dir/all] Error 2
make[1]: Leaving directory `/work/jias12/jias1217/test'
make: *** [all] Error 2
If I rerun the last argument without the -rdynamic
mpixlf2008 -static -O2 -qarch=qp -qtune=qp -ufmt_littleendian={23} CMakeFiles/test.x.dir/src/test1.o -o test.x
I get the error:
/bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/bin/ld: -f may not be used without -shared
How can I compile my program using statically using CMake? If I simply run:
mpixlf2008 -c src/test1.f90
mpixlf2008 test1.o -o bla.x
The compilation works fine and the size(45M) suggest, that it's compiled statically.
Edit:
If I remove the little endian flag:
set(dialect "-O2 -qarch=qp -qtune=qp")
I can run the cmake created makefile and then manually remove the -rdynamic
mpixlf2008 -static -O2 -qarch=qp -qtune=qp CMakeFiles/test.x.dir/src/test1.o -o test.x
Which then successfully compiles. How can I remove the -rdynamic from the CMake Makefile?
Try adding -qstaticlink to your link line instead of adding -static / -rdynamic directly. When you use the mpixlf2008 command, the compiler inserts its own -static / -rdynamic options to link in its own libraries, so the options you added are probably interfering with the ones the compiler is using. The -qstaticlink option tells the compiler you want a completely static binary. The option also has suboptions that would allow you to only statically link the gcc libraries.
Also, the specific error you're getting is because you specified "-rdynamic". XLF doesn't know this option, so it assumes it's a grouping of smaller options. So it parses it as: "-r -d -ynamic". -r is for creating a nonexecutable output file, -d is for saving preprocessed output, -y is for specifying compile-time rounding mode. The -y option takes a suboption for the rounding mode, e.g. -yn for nearest. The error you're getting is that namic is not a known suboption of -y. To pass -rdynamic to the linker, put -Wl, before it. i.e. "-Wl,-rdynamic".
Adding
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
allows me to remove the '-rdynamic'. This might be a bit manual, but for older CMake versions it works.

cmake package_search_module for glfw3 finds package, doesn't supply full lib path

This seems pretty straightforward but I'm wasting enormous amounts of time getting it working. I just want to build and link a main.cpp file that includes glfw3.h, but cmake is not seeing the lib path for GLFW. the call to package_search_module is providing the right include dir, but the resulting GLFW_LIBRARIES value only has the lib name 'glfw3' in it and its dir is not being given on the command line for the build.
What am I missing here?
Here is my very simple CMakeFiles.txt:
cmake_minimum_required(VERSION 3.3)
project(gltest)
set(CMAKE_VERBOSE_MAKEFILE true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(gltest ${SOURCE_FILES})
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(gltest ${GLFW_LIBRARIES})
message("GLFW_LIBRARIES=${GLFW_LIBRARIES}")
And here is the build output, where you can see at the top there that GLFW_LIBRARIES contains 'glfw3':
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --target all -- -j 8
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/dave/dev/gltest -B/Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --check-build-system CMakeFiles/Makefile.cmake 0
GLFW_LIBRARIES=glfw3
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/depend
cd /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/dave/dev/gltest /Users/dave/dev/gltest /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/gltest.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/build
[ 50%] Linking CXX executable gltest
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/gltest.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++11 -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/gltest.dir/main.cpp.o -o gltest -lglfw3
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [gltest] Error 1
make[1]: *** [CMakeFiles/gltest.dir/all] Error 2
make: *** [all] Error 2
And, finally, here is the glfw3.pc pkg-config that is used for the pkg_search_module call:
prefix=/usr/local/Cellar/glfw3/3.2.1
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: GLFW
Description: A multi-platform library for OpenGL, window and input
Version: 3.2.1
URL: http://www.glfw.org/
Requires.private:
Libs: -L${libdir} -lglfw3
Libs.private: -framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo
Cflags: -I${includedir}
~
Update: I got it working with this, but it still feels wrong
cmake docs recommend against using link_directories, but I am able to make this work by using that and building up a list of link libraries:
set(LINK_LIBRARIES )
# GLFW lib
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
link_directories(${GLFW_LIBRARY_DIRS})
set(LINK_LIBRARIES ${LINK_LIBRARIES} ${GLFW_LIBRARIES})
add_executable(gltest ${SOURCE_FILES})
target_link_libraries(gltest ${LINK_LIBRARIES})
You need <XPREFIX>_LDFLAGS (all required linker flag) and maybe <XPREFIX>_LDFLAGS_OTHER (all other linker flags) with <XPREFIX> = GLFW, acccording to the documentation https://cmake.org/cmake/help/v3.6/module/FindPkgConfig.html

cmake cxx flags only at compile time

I wanted to know if there is a way to pass some flags to the compiler (g++) only at compile time and not at the linking.
Let me explain with an example: I would like to build my program this way:
g++ -c source1.cpp -o source1.o
g++ -c source2.cpp -o source2.o
g++ source2.o source1.o -o myProgram.c
to do this I have created a CMakeLists.txt file that contains:
PROJECT(myProgram)
include_directories("${CMAKE_SOURCE_DIR}/inc")
aux_source_directory("${CMAKE_SOURCE_DIR}/src" SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
then add this line to put the "-c" flag to the compiler:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
But in this way, cmake add the "-c" flag always, even when g++ is doing the linking, ie:
g++ -c source1.cpp -o source1.o
g++ -c source2.cpp -o source2.o
g++ -c source2.o source1.o -o myProgram.c
and logically myProgram will not be created because the g++ does not run linking (-c in the last instruction).
How do I use the flag "-c" (or any other flag) only at compile?
Instead of
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
try
add_compile_options(-c)
No clue why though. You can use multiple space separated options in the same add_compile_options.
I am using this "CMakeLists.txt"
PROJECT(prima_prova)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_VERBOSE_MAKEFILE 1)
include_directories("${CMAKE_SOURCE_DIR}/inc")
aux_source_directory("${CMAKE_SOURCE_DIR}/src" SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
when I run cmake .. and make, I get this:
make[2]: uscita dalla directory "/home/massimi/Scrivania/test/build"
make -f CMakeFiles/prima_prova.dir/build.make CMakeFiles/prima_prova.dir/build
make[2]: ingresso nella directory "/home/massimi/Scrivania/test/build"
[ 25%] Building CXX object CMakeFiles/prima_prova.dir/src/f1.cpp.o
/usr/bin/c++ -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f1.cpp.o -c /home/massimi/Scrivania/test/src/f1.cpp
[ 50%] Building CXX object CMakeFiles/prima_prova.dir/src/main.cpp.o
/usr/bin/c++ -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/main.cpp.o -c /home/massimi/Scrivania/test/src/main.cpp
[ 75%] Building CXX object CMakeFiles/prima_prova.dir/src/f2.cpp.o
/usr/bin/c++ -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f2.cpp.o -c /home/massimi/Scrivania/test/src/f2.cpp
[100%] Linking CXX executable prima_prova
/usr/bin/cmake -E cmake_link_script CMakeFiles/prima_prova.dir/link.txt -- verbose=1
/usr/bin/c++ CMakeFiles/prima_prova.dir/src/f1.cpp.o CMakeFiles/prima_prova.dir/src/main.cpp.o CMakeFiles/prima_prova.dir/src/f2.cpp.o -o prima_prova -rdynamic
make[2]: uscita dalla directory "/home/massimi/Scrivania/test/build"
when I add this line in the file "CMakeLists.txt":
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
when I run cmake .. and make, I get this:
make[2]: uscita dalla directory "/home/massimi/Scrivania/test/build"
make -f CMakeFiles/prima_prova.dir/build.make CMakeFiles/prima_prova.dir/build
make[2]: ingresso nella directory "/home/massimi/Scrivania/test/build"
[ 25%] Building CXX object CMakeFiles/prima_prova.dir/src/f1.cpp.o
/usr/bin/c++ -c -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f1.cpp.o -c /home/massimi/Scrivania/test/src/f1.cpp
[ 50%] Building CXX object CMakeFiles/prima_prova.dir/src/main.cpp.o
/usr/bin/c++ -c -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/main.cpp.o -c /home/massimi/Scrivania/test/src/main.cpp
[ 75%] Building CXX object CMakeFiles/prima_prova.dir/src/f2.cpp.o
/usr/bin/c++ -c -I/home/massimi/Scrivania/test/inc -o CMakeFiles/prima_prova.dir/src/f2.cpp.o -c /home/massimi/Scrivania/test/src/f2.cpp
[100%] Linking CXX executable prima_prova
/usr/bin/cmake -E cmake_link_script CMakeFiles/prima_prova.dir/link.txt --verbose=1
/usr/bin/c++ -c CMakeFiles/prima_prova.dir/src/f1.cpp.o CMakeFiles/prima_prova.dir/src/main.cpp.o CMakeFiles/prima_prova.dir/src/f2.cpp.o -o prima_prova -rdynamic
c++: warning: CMakeFiles/prima_prova.dir/src/f1.cpp.o: linker input file unused because linking not done
The flag "-c" or any iother flag in the variable CMAKE_CXX_FLAGS has been added always, even during linking, not only when is compiling sources.
CMAKE_CXX_FLAGS variable is used in command line only when CMake is compiling sources. During linking CMAKE_EXE_LINKER_FLAGS (and flags set by modifying target properties) are used, even if g++ is used as linker executable.