[英]Chain of C libraries into C++
I have a very trivial problem including a chain of C libraries into a C++ main project. 我有一个非常琐碎的问题,包括将C库链接到C ++主项目中。 I've experience with C but it's the first time that I'm programming in C++.
我有C的经验,但这是我第一次用C ++进行编程。
The structure of the project is a single folder with inside: 该项目的结构是一个单独的文件夹,内部有:
main calls -> Mylib_1.h that calls -> My_lib2.h 主调用-> Mylib_1.h,调用-> My_lib2.h
//main.cpp
#include "Mylib_1.h"
//Mylib_1.h
#include "Mylib_2.h"
main contains both Mylib_1 and Mylib_2 functions and typedef structs main包含Mylib_1和Mylib_2函数以及typedef结构
Mylib_1 uses typedef structs and functions of Mylib_2 Mylib_1使用Mylib_2的typedef结构和函数
Everything inside each Mylib_x.h is wrapped between extern "C", like this: 每个Mylib_x.h内部的所有内容都包装在外部“ C”之间,如下所示:
#ifndef __MYLIB_X_H
#define __MYLIB_X_H
#ifdef __cplusplus
extern "C" {
#endif
mycode
#ifdef __cplusplus
}
#endif
#endif
But when I try to compile it with eclipse kepler on Ubuntu 12.04 x64, I get: 但是,当我尝试在Ubuntu 12.04 x64上使用eclipse kepler对其进行编译时,我得到:
Mylib_1.h error: Mylib_2_type_t does not name a type
Mylib_1.h错误:Mylib_2_type_t没有命名类型
main.cpp error: Mylib_2_function1 was not declared in this scope
main.cpp错误:在此作用域中未声明Mylib_2_function1
...
...
Only the above sections are marked as error in eclipse, the header looks included fine. 仅上述部分在eclipse中被标记为错误,标题看起来还不错。
Furthermore according to eclipse, the __cplusplus flag is false into Mylib_2.h but true into Mylib_1.h 此外,根据eclipse,__cplusplus标志在Mylib_2.h中为false,在Mylib_1.h中为true。
Thinking of some eclipse error, I've tried to manually build the project via g++ (v4.6.3) but I got the same exact problem when I've tried to link the libraries .o with the main.cpp 考虑到一些月食错误,我试图通过g ++(v4.6.3)手动构建项目,但是当我尝试将库.o与main.cpp链接时,我遇到了同样的问题。
Seems stupid but I can't figure out what could it be. 看起来很愚蠢,但我不知道会是什么。 Any suggestion?
有什么建议吗?
Thank you 谢谢
Have you checked that your lines 你检查过你的台词了吗
#ifndef __MYLIB_X_H
#define __MYLIB_X_H
are really different for the two files, eg _ MYLIB 1 _H and _ MYLIB 2 _H? 两个文件(例如_ MYLIB 1 _H和_ MYLIB 2 _H)确实有什么不同?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.