Reputation: 13222
I want to get two executables from my C++ source code (test and release). I have two main() functions in two separate C++ files.
With the Meson build system it is easy:
project('PrjName', 'cpp')
mainSrc = ['header1.hpp', 'source1.cpp', 'source2.cpp']
testSrc = ['header2.hpp', 'source2.cpp', 'test.cpp']
mainExe = executable('prjName', mainSrc)
testExe = executable('prjNameTest', testSrc)
I could not get the same with CMake:
cmake_minimum_required(VERSION 3.10)
project("PrjName")
set(SOURCES
"header1.hpp"
"source1.cpp"
"source2.cpp"
)
set(TEST_SOURCES
"header2.hpp"
"source2.cpp"
"test.cpp"
)
add_executable("prjName" ${SOURCES})
add_executable("prjNameTest" ${TEST_SOURCES})
I get the first executable (prjName), but not the second, with the error:
Multiple definition of 'main'
However, the main() functions are defined in "source1.cpp" and "test.cpp", so there should be no conflict.
How can I fix this issue, considering that as it seems from the Meson build the code should be fine?
Upvotes: 0
Views: 769
Reputation: 13222
Building the same code on a different PC, I had no such issue.
I would close/delete this question.
Upvotes: 1