Search code examples
assemblycmakelinker-scripts

cmake assembly: /usr/bin/ld: no input files


I'm trying to familiarize myself with cmake and I've chosen a very simple hobby kernel written in assembly as a test-bed. The problem is, it seems like the linker is called prior to compiling the sources, I'm getting this error:

$ make
[100%] Linking ASM-ATT executable kernel
/usr/bin/ld: no input files
CMakeFiles/kernel.dir/build.make:69: recipe for target 'kernel' failed
make[2]: *** [kernel] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/kernel.dir/all' failed
make[1]: *** [CMakeFiles/kernel.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Here's the CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
project(kernel ASM-ATT)

enable_language(ASM-ATT)

set(CMAKE_ASM-ATT-COMPILER as)

set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/linker.ld)
set(CMAKE_EXE_LINKER_FLAGS "-N -T${LINKER_SCRIPT}")

add_executable(${CMAKE_PROJECT_NAME}
    multiboot.S
    start.S
    )

set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
    LINK_DEPENDS "${LINKER_SCRIPT}"
    LINKER_LANGUAGE ASM-ATT
    )

I assume there's something obvious I'm missing here. What's the proper way to build assembly with a custom linker script?


Solution

  • With CMake, error message

    /usr/bin/ld: no input files
    

    usually means that CMake doesn't recongnize any file, passed to add_executable/add_library command, as source file.

    In the given case .S files are not treated by CMake as assembler files for ASM-ATT language. Wiki page, which describes assembling with CMAKE, explicitely states that:

    .S files, i.e. assembler files which require preprocessing, are not supported

    If your assembler files are not required preprocessing, you may rename them to .s or .asm files, so CMake will treat them as source files for given language.