0

I have a project which must be build for two different architectures. I am running a x86_64 Linux machine with gcc installed at default path and also I have a cross-compiler gcc for second PowerPC Linux machine.

I have one CMakeLists.txt file where compiler choice depends on passed variable.

The problem is that when it uses not default compiler it somehow uses default linker that obviously can not link the executable with provided libraries.

So, I set

set(CMAKE_C_COMPILER ${tools}/bin/powerpc-e500v2-linux-gnuspe-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/powerpc-e500v2-linux-gnuspe-g++)

so it would use my cross-compiler but then there are errors in console

/usr/bin/ld: skipping incompatible /home/namtarr/Documents/libevent/usr/lib/powerpc-linux-gnuspe/libevent.a when searching for -levent

If I try to set

set(CMAKE_C_LINK_EXECUTABLE ${tools}/bin/powerpc-e500v2-linux-gnuspe-ld)
set(CMAKE_CXX_LINK_EXECUTABLE ${tools}/bin/powerpc-e500v2-linux-gnuspe-ld)

it throws another error

/home/namtarr/x-tools/powerpc-e500v2-linux-gnuspe/bin/powerpc-e500v2-linux-gnuspe-ld: no input files

So how can I properly set linker in Cmake and pass needed input files to it so I could build my project for two platforms with one CMakeLists.txt?

Anton Tarasov
  • 536
  • 5
  • 12
  • `it somehow uses default linker` - Strange, usually CMake uses compiler itself (with appropriate options) for linking. Can you provide your `CMakeLists.txt` (as [mcve])? As for variable [CMAKE_C_LINK_EXECUTABLE](https://cmake.org/cmake/help/v3.7/variable/CMAKE_LANG_LINK_EXECUTABLE.html), it denotes **rule** for linking, not just a linker executable. – Tsyvarev Apr 20 '17 at 07:58
  • Possible duplicate of [force cmake specific sh path](http://stackoverflow.com/questions/43049747/force-cmake-specific-sh-path). Using [`CMAKE_IGNORE_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_IGNORE_PATH.html) to exclude the other toolchain from any of CMake's program searches should work in this case also. – Florian Apr 20 '17 at 18:54
  • @Florian: Why do you think that a *shell* is a problem here? Cross-compiler toolchains on Linux usually don't provide specific shell, host shell is sufficient for them. – Tsyvarev Apr 21 '17 at 07:47
  • @Tsyvarev I admit the title is misleading there. But having two toolchains in the `PATH` is what the question and answer does discuss. So I think that excluding one of the toolchains with `CMAKE_IGNORE_PATH` would prevent CMake from mixing programs from both toolchains. – Florian Apr 21 '17 at 07:50
  • @Florian: As far as I understand, there is *only one toolchain* in the question - for PowerPC. There is also a *host* compiler, which is installed at default path. Normally, host compiler shouldn't prevent toolchain to work. Moreover, the author even doesn't use *toolchain* in CMake sence: he just redefines a compiler. – Tsyvarev Apr 21 '17 at 08:19

0 Answers0