0

Ouch! I inadvertently updated CMake to 3.9.1 (long story, and I don't know the old version), which is not terribly new, but is what Ubuntu/PopOS! 17.10 seem to support, and now my project failed to find my tools. Okay, I said, my original toolchain file used the obsolete/deprecated "force toolchain" thing, which was given to me several years ago. Having recently learned the correct way, I updated my toolchain file, and all works fine - until it is time to link. Now, the link fails with no input files; in other words, the command looks like this:

ld

There were no changes to my CMakeLists.txt file, and I am stumped! What could cause the link command to change so drastically?

Here is the new toolchain file:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(XILINX_ROOT /home/bgrimes/osu/tools/opt/pkg/petalinux)
set(XILINX_TOOLS ${XILINX_ROOT}/tools/linux-i386/gcc-arm-linux-gnueabi)
set(CMAKE_C_COMPILER "${XILINX_TOOLS}/bin/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "${XILINX_TOOLS}/bin/arm-linux-gnueabihf-g++")
set(CMAKE_CXX_LINK_EXECUTABLE "${XILINX_TOOLS}/bin/arm-linux-gnueabihf-ld")

#set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-a9" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfpv3" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXILINX" )

set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions")

Here is the old toolchain file:

INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME "Linux")
CMAKE_FORCE_C_COMPILER(arm-linux-gnueabihf-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(arm-linux-gnueabihf-g++ GNU)

set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-a9" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfpv3" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXILINX" )
set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions" )

set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" FORCE )
set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" FORCE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE )
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Bob
  • 587
  • 8
  • 17
  • Variable [CMAKE_CXX_LINK_EXECUTABLE](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_LINK_EXECUTABLE.html) denotes the **rule** for link, not just a *linker*. See e.g. this answer about setting this variable in the command line, you may adapt it to the toolchain setting. – Tsyvarev Jun 05 '20 at 08:37
  • Doh! Don't know why this worked in the other project - probably didn't but something else die - but simply deleting this fixes everything!!! Make this an answer so I can upvote it - you were exactly correct! THANKS! – Bob Jun 05 '20 at 22:04

1 Answers1

1

Variable CMAKE_CXX_LINK_EXECUTABLE denotes the rule for link, not just a linker.

So setting it with

set(CMAKE_CXX_LINK_EXECUTABLE "${XILINX_TOOLS}/bin/arm-linux-gnueabihf-ld")

effectively makes the linker to be called without any arguments.

Common way to set this variable is:

set(CMAKE_LINKER "${XILINX_TOOLS}/bin/arm-linux-gnueabihf-ld")
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

See also that answer: CMake: use a custom linker.


Note, that CMAKE_LINKER variable is not a special variable by itself: CMake knows nothing about it. In the example above this variable is referred via <CMAKE_LINKER> construction in the rule.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153