I'm trying to compile a function in C++ and then take the output object file and compile it into a C function. I'm getting an error during linking. Here's the code:
row_executor.c:
#include "row_exec.h"
void row_executor(char* row) {
row_exec(row);
return;
}
row_exec.h
#ifndef ROWEXEC_CPP_H
#define ROWEXEC_CPP_H
#ifdef __cplusplus
//fill in C++ code here later
#endif
#ifdef __cplusplus
extern "C" {
#endif
void row_exec(char* rowname);
#ifdef __cplusplus
} //end extern "C"
#endif
#endif
row_exec.cpp:
#ifdef __cplusplus
#include "row_exec.h"
#include <iostream>
using namespace std;
void row_exec(char* rowname) {
cout << "Row name is: " << rowname << endl;
}
#endif
The C++ object file is generated by makefile entry:
row_exec.o: row_exec.cpp row_exec.h
g++ -Wall -c row_exec.cpp
The C object file is generated by:
gcc -c -I<include paths> -g -fPIC -DPIC -o row_exec.o row_executor.c
Both generate object files fine, but when the row_executor.o gets linked together with a bunch of other unrelated object files corresponding to other tests, I get the following error:
row_executor.o(.text+0x1a): In function row_executor':
/LAB/MODULES/rev_13~~/row_executor.c:4: undefined reference to
row_exec'
collect2: ld returned 1 exit status
make: *** [hm_prod_rev_16.so] Error 1
Does anyone see the issue?