【发布时间】:2016-07-15 01:32:39
【问题描述】:
我试图从 C 调用 C++。我不确定链接顺序。这可能是导致错误的原因。由于某些原因,编译器会抱怨undefined reference to helloWorld。
有人可以建议吗?
main.c:
#include "example.h"
#include <stdio.h>
int main(){
helloWorld();
return 0;
}
example.h:
#ifndef HEADER_FILE
#define HEADER_FILE
#ifdef __cplusplus
extern "C" {
#endif
void helloWorld();
#ifdef __cplusplus
}
#endif
#endif
example.cpp:
#include "example.h"
#include <iostream>
void helloWorld(){
std::cout << "Hello World from CPP";
}
【问题讨论】:
-
应该可以,我只能假设你没有链接到
example.cpp(example.o)。