Compile C with C++ files together
This commit is contained in:
parent
e4f3239a37
commit
ba0d09b6c4
@ -1,7 +1,7 @@
|
|||||||
# DO NAME THE SYMBOLIC VARIABLE `SOURCES`
|
# DO NAME THE SYMBOLIC VARIABLE `SOURCES`
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
set(SOURCES src/main.cpp)
|
set(SOURCES src/main.cpp src/hello.c)
|
||||||
|
|
||||||
# DO NOT EDIT THE FOLLOWING LINE
|
# DO NOT EDIT THE FOLLOWING LINE
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
|
13
template_cpp/src/include/hello.h
Normal file
13
template_cpp/src/include/hello.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void hello();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
11
template_cpp/src/src/hello.c
Normal file
11
template_cpp/src/src/hello.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "hello.h"
|
||||||
|
|
||||||
|
void hello() {
|
||||||
|
printf("Source file that end in .c will be compiled automatically with gcc,\n"
|
||||||
|
"while files that end in .cpp will be compiled automatically with g++.\n"
|
||||||
|
"For those that prefer C, they can either use the provided C++\n"
|
||||||
|
"argument parser and write everything else in C, or delete the\n"
|
||||||
|
"provided main.cpp and start from scratch.\n"
|
||||||
|
"Make sure to have compatible ABI when calling C functions from cpp:\n"
|
||||||
|
"See `hello.h` on how to do this.\n");
|
||||||
|
}
|
@ -4,8 +4,10 @@
|
|||||||
|
|
||||||
#include "barrier.hpp"
|
#include "barrier.hpp"
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
|
#include "hello.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
|
||||||
static void stop(int) {
|
static void stop(int) {
|
||||||
// reset signal handlers to default
|
// reset signal handlers to default
|
||||||
signal(SIGTERM, SIG_DFL);
|
signal(SIGTERM, SIG_DFL);
|
||||||
@ -32,6 +34,9 @@ int main(int argc, char **argv) {
|
|||||||
Parser parser(argc, argv, requireConfig);
|
Parser parser(argc, argv, requireConfig);
|
||||||
parser.parse();
|
parser.parse();
|
||||||
|
|
||||||
|
hello();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
std::cout << "My PID: " << getpid() << "\n";
|
std::cout << "My PID: " << getpid() << "\n";
|
||||||
std::cout << "Use `kill -SIGINT " << getpid() << "` or `kill -SIGTERM "
|
std::cout << "Use `kill -SIGINT " << getpid() << "` or `kill -SIGTERM "
|
||||||
<< getpid() << "` to stop processing packets\n\n";
|
<< getpid() << "` to stop processing packets\n\n";
|
||||||
@ -81,5 +86,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::cout << "Broadcasting messages...\n\n";
|
std::cout << "Broadcasting messages...\n\n";
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(60));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user