I'm trying to cross compile from Ubuntu to Windows, using CMake. I have everything configured (Installed both mingw32 and mingw64), and I have the relevant toolchain files for both. The problem is that a variable that I set in one toolchain file, after it is used, persists in the second run with the other toolchain file one as well.
These are my toolchain files:
Windows 64 bit: (Toolchain-Ubuntu-mingw64.cmake)
set(CMAKE_SYSTEM_NAME Windows)
unset(PROCESSOR_ARCHITECTURE CACHE)
set(PROCESSOR_ARCHITECTURE x64)
message("===Processor architecture: " ${PROCESSOR_ARCHITECTURE})
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Windows 32 bit: (Toolchain-Ubuntu-mingw32.cmake)
set(CMAKE_SYSTEM_NAME Windows)
unset(PROCESSOR_ARCHITECTURE CACHE)
set(PROCESSOR_ARCHITECTURE x86)
message("===Processor architecture: " ${PROCESSOR_ARCHITECTURE})
set(TOOLCHAIN_PREFIX i686-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
And this is the top of my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
project("project")
set(SOURCE_FILE_LIST main.c)
set(ARCH_PROJECT_NAME ${PROJECT_NAME}${PROCESSOR_ARCHITECTURE})
message("Project - " ${ARCH_PROJECT_NAME})
...
When I run
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchains/Toolchain-Ubuntu-mingw64.cmake ../src/
The output starts with:
===Processor architecture: x64
Project - projectx64
The unexpected part comes when I run:
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchains/Toolchain-Ubuntu-mingw32.cmake ../src/
and the output still starts with
===Processor architecture: x64
Project - projectx64
What can I do to fix this behaviour?
CMake will cache many of the values it finds during the setup process. Frustratingly it does this to the point that attempting to recreate the projects with a new option specified on the command line simply doesn't work. The only solution I've found is to either delete the entire build directory, or the specific cache file in the build directory, called CMakeCache.txt I believe.
Related
I have been trying to make a program for Windows with C++ and Linux. I imported some libraries and wrote the code. Now this is the config for CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_FLAGS "-std=c++14 -DCMAKE_BUILD_TYPE=release64 -m32")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
project(qpsm)
add_executable(
a.exe
main.cpp
)
add_executable(
a.run
main.cpp
)
I know it's not very efficent, but it does the job for Linux. When it compiles for Windows and I try to open it on a Windows Machine it gives me the error with the title Not supported 16 Bit-Application that a feature called "\??\C:\Users\kroyz\Downloads\a.exe" cannot be run due to a incompatibility with 64-Bit Versions.
I know I am very bad at trying to explain things and errors so let me know if I did something wrong
Regards,
Alex
I'm trying to cross compile to an ARM with linux from my x86 with a linux.
The issue appears to be that when including some standard library headers like iostream or string, even if those are included from the path where the cross compiler is, and its standard library, some of the dependencies of those headers seems to be included from my local standard library.
The headers from my local standard library have some x86 specific type definitions which do not exist on ARM hence the compilation fails.
The error shown is:
[01m[K/usr/include/bits/floatn.h:87:9:[m[K [01;31m[Kerror: [m[K?[01m[K__float128[m[K? does not name a type; did you mean ?[01m[K__cfloat128[m[K??
87 | typedef [01;31m[K__float128[m[K _Float128;
| [01;31m[K^~~~~~~~~~[m[K
| [32m[K__cfloat128[m[K
In file included from [01m[K/opt/fslc-wayland/3.1/sysroots/aarch64-fslc-linux/usr/include/c++/9.3.0/cwchar:44[m[K,
from [01m[K/opt/fslc-wayland/3.1/sysroots/aarch64-fslc-linux/usr/include/c++/9.3.0/bits/postypes.h:40[m[K,
from [01m[K/opt/fslc-wayland/3.1/sysroots/aarch64-fslc-linux/usr/include/c++/9.3.0/iosfwd:40[m[K,
from [01m[K/opt/fslc-wayland/3.1/sysroots/aarch64-fslc-linux/usr/include/c++/9.3.0/ios:38[m[K,
from [01m[K/opt/fslc-wayland/3.1/sysroots/aarch64-fslc-linux/usr/include/c++/9.3.0/ostream:38[m[K,
from [01m[K/opt/fslc-wayland/3.1/sysroots/aarch64-fslc-linux/usr/include/c++/9.3.0/iostream:39[m[K,
from [01m[K/home/lorandpetok/cross_ws/src/rvc_robot/rvc_ui/include/ConsoleMenu.h:5[m[K,
from [01m[K/home/lorandpetok/cross_ws/src/rvc_robot/rvc_ui/src/ConsoleMenu.cpp:1[m[K:<
Here you can see that I include iostream, the includes cascade down to cwchar which in turn includes floatn.h from my local x86 library.
The compiler used for cross compilation is gcc 9.3.0
My cmake toolchain file used:
set(ARTHERO_SYSROOTS "/opt/fslc-wayland/3.1/sysroots")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv8-a)
set(TOOLCHAIN_PREFIX ${ARTHERO_SYSROOTS}/x86_64-fslcsdk-linux/usr/bin/aarch64-fslc-linux/aarch64-fslc-linux-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_SYSROOT ${ARTHERO_SYSROOTS}/aarch64-fslc-linux)
set(CMAKE_PREFIX_PATH ${CMAKE_SYSROOT}/usr/lib/cmake ${CMAKE_SYSROOT}/opt/ros/melodic/share)
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT} ${CATKIN_DEVEL_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_MODULE_PATH ${CMAKE_SYSROOT}/opt/ros/melodic/share)
set(LD_LIBRARY_PATH ${CMAKE_SYSROOT}/opt/ros/melodic/lib)
set(COMPILER_FLAGS " -march=armv8-a -mtune=cortex-a53")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}" CACHE STRING "" FORCE)
include_directories(/opt/fslc-wayland/3.1/sysroots/aarch64-fslc-linux/opt/ros/melodic/include/)
What could make the compiler or cmake to include the header from my local standard library and how should i tell it to look in the correct path?
I am trying to compile a simple program made in C++ from windows to my raspberry pi 4 B.
For that I use Cmake but I don't know what to use to compile the program. Visual Studio it seems can compile Arm and Arm64 but according to the documentation, the Rp4 is in ArmV8 and when I do uname -m on the Rp4 I get armv71. I don't know what to indicate in CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)
set(CMAKE_STAGING_PREFIX /home/devel/stage)
set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
project(SCWWS CXX)
#=================== INCLUSION OF Project Files ====================#
set(FORMS_DIR "${CMAKE_SOURCE_DIR}/forms")
set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
set(SOURCE_DIR "${CMAKE_SOURCE_DIR}/src")
include_directories(${FORMS_DIR})
include_directories(${INCLUDE_DIR})
include_directories(${SOURCE_DIR})
file(GLOB_RECURSE SOURCES
"${INCLUDE_DIR}/*.h"
"${SOURCE_DIR}/*.cpp"
)
#=================== SETUP EXECTUABLE ====================#
# Add the executable
add_executable(SCWWS ${SOURCES})
# Add the target includes for SCWWS
target_include_directories(SCWWS PRIVATE ${FORMS_DIR})
target_include_directories(SCWWS PRIVATE ${INCLUDE_DIR})
target_include_directories(SCWWS PRIVATE ${SOURCE_DIR})
When I run my program on the Rp4 I get this error:
-bash: ./SCWWS: cannot execute binary file: Exec format error
For now, here is the cpp code that I am compiling:
#include <iostream>
using namespace std;
int main(){
cout << "Hello World !";
return 0;
}
For later, I would like to make a Qt application, will there be anything else to do?
I am using a WSL running Ubuntu and am trying to get an SDL2 program to compile using the Ubuntu and then run the program on Windows. I have been able to get it to build, however it doesn't make an exe (and changing the file extension to exe doesn't fix it). Also even though I set the CMAKE_CXX_FLAGS to have -o Crawl_The_Dungeon.exe the file still ends up being named all lower case like the project name. I was able to get this to compile and run on linux when I still had a linux machine.
I am still pretty new to CMake so I don't fully understand if I am close at all or not at all.
SET(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_CXX_STANDARD 14) # Enable c++14 standard
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${crawl_the_dungeon_SOURCE_DIR}/CMakePath")
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
project(crawl_the_dungeon)
set(SOURCE_FILES final.cpp Soldier.cpp TilesEnum.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --static -std=c++0x")
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR})
target_link_libraries(crawl_the_dungeon ${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES}
)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc")
EDIT: I was dumb to include -o Crawl_The_Dungeon.exe as it now creates an exe. However it says that I can't run the program when opening it.
I am trying to make a cross-compilation toolchain script for my BeagleBoard XM, but it doesn't work : the basic c++ includes (<algorithm>, etc...) aren't found when compiling.
Here is my toolchain file, made by following these two tutorials:
http://clang.llvm.org/docs/CrossCompilation.html
http://www.cmake.org/Wiki/CMake_Cross_Compiling#The_toolchain_file
The file:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(FLOAT_ABI_SUFFIX "")
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_FLAGS "-target armv7a-unknown-eabi -mfloat-abi=hard -mcpu=cortex-a8 --sysroot=/mnt/beagle/")
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /mnt/beagle /mnt/beagle/usr)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
/mnt/beagle is a SD Card with a copy of the system in my BeagleBoard, with all the necessary development packages, etc. installed.
Both the host and the guest are under Debian Jessie.
As a side question, I also have the android SDK & NDK installed. Is it possible to use them as a cross-compile environment, since it's ARMv7, or does the android NDK bring significant changes ?