小编use*_*375的帖子

从C文件调用C++函数

我是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.这个问题在哪里?

c c++ merge call

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

c ×1

c++ ×1

call ×1

merge ×1