- 论坛徽章:
- 0
|
各位大虾,小弟的程序是用c++写的,现在要调用一个用c编写的程序模块。c程序模块是作为一个静态库调用的,名字为libmodule.a
,在当前目录下。在我的c++代码中,如果加入#include <iostream>或者#include <iostream>等流操作头文件,程序链接的时候就
会出错;其他加入#include <string>等stl头文件,程序运行正常。
我的c++代码和Makefile如下:
我的c++文件仅为一个main.cpp文件,用来测试是否能够正常链接。
- // main.cpp
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- #include "header_file_of_c_module.h" /* header_file_of_c_module.h is one of the header files of the c module */
- #ifdef __cplusplus
- }
- #endif
- #include <string>
- int main(int argc, char * argv[])
- {
- string str;
- str = fun_of_c_module();
- return 0;
- }
复制代码
- #Makefile
- CC= g++
- CPPFLAGS = -g -Wall
- OBJS = main.o
- exe: $(OBJS)
- $(CC) $(CPPFLAGS) -o exe $(OBJS) -lmodule -L.
- %.o: %.cpp
- $(CC) $(CPPFLAGS) -c $< -o $@
- clean:
- rm -f $(OBJS) exe
复制代码 |
|