Reputation: 8942
I have decided to make a C++-Qt-GUI for a C program (both languages I don’t know), using KDevelop, which in turn uses CMake.
The C source has no header, so I made one, and migrated some structs into it, as well as the declaration of the only function in the C source i need to call.
The problem is that I can’t call it, because either CMake doesn’t find the C file (and hence the definition), or, when I add the C source to my source set in the CMakeLists.txt, it complains that both my main.cpp and the C source file have main functions.
How do I tell CMake that it should only make the function from the C file available which I declared in the header?
here is it:
project(oregengui)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
set(oregengui_SRCS oregengui.cpp main.cpp qrangeslider/qrangeslider.cpp)
#as soon as i add oregengui/oregengui.c, it won’t work because of the main function
qt4_automoc(${oregengui_SRCS})
add_executable(oregengui ${oregengui_SRCS})
target_link_libraries(oregengui ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
PS: I don’t want to change the C source too much, since it is a independant project. I guess the developer will accept the introduction of the header, but not much more.
Upvotes: 4
Views: 2267
Reputation: 3723
Try compiling C file as library and linking it with executable.
add_library(clib oregengui/oregengui.c)
[...]
add_executable(oregengui ${oregengui_SRCS})
target_link_libraries(oregengui ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} clib)
Upvotes: 2
Reputation: 7982
I'm a bit rusty on this, but could you do something along the lines of:
In oregengui.c
#if !defined MYGUIPROJ
int main() {
...
}
#endif
In your CMakeLists that you want both in:
add_definitions( -DMYGUIPROJ )
The compiler should then ignore your second main function.
Upvotes: 1
Reputation: 8019
if your C program has a main function, then it can be executed independently. So why not use the QProcess::execute() method to invoke the application from qt and get the output?
Upvotes: 0
Reputation: 11636
Your program cannot contain two main functions at the same time. Just try to rename the main function in the C file you included to your project. This is not a big change to the source, but you will have to do it locally.
Upvotes: 0