Linking one executable against another executable with ENABLE_EXPORTS doesn't work.
cmake_minimum_required(VERSION 3.14)
project(Issue19519 C)
add_executable(foo foo.c)
set_property(TARGET foo PROPERTY ENABLE_EXPORTS 1)
add_executable(bar bar.c)
target_link_libraries(bar foo)
Declare a simple function in foo.h, define it in foo.c and use it in bar.c. Building fails with the following message:
ninja: Entering directory `build'
[0/1] Re-running CMake...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/daan/projects/test/build
[2/2] Linking C executable bar
FAILED: bar
: && /usr/bin/cc CMakeFiles/bar.dir/bar.c.o -o bar && :
/usr/bin/ld: CMakeFiles/bar.dir/bar.c.o: in function `main':
bar.c:(.text+0x15): undefined reference to `test'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Everything works if bar is changed to a library.
Tested on Arch Linux with GCC 9.1.0 and CMake 3.15.