我是C和C++的新手.但我有一些C++函数,我需要从C调用它们.我做了一个我需要做的例子
main.c:
#include "example.h"
#include <stdio.h>
int main(){
helloWorld();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
example.h:
#ifndef HEADER_FILE
#define HEADER_FILE
#ifdef __cplusplus
extern "C" {
#endif
void helloWorld();
#ifdef __cplusplus
}
#endif
#endif
Run Code Online (Sandbox Code Playgroud)
example.cpp:
#include <iostream.h>
void helloWorld(){
printf("hello from CPP");
}
Run Code Online (Sandbox Code Playgroud)
它只是不起作用.我仍然收到未定义参考错误_helloWorld在我main.c.这个问题在哪里?