Is there a way to #include "library.a" or it's 开发者_如何学C.so or it's .o inside a cpp or cc file?
I would like to do this because I am using this file inside another file.
#include
is for C++ code.
.a
, .so
and .o
files are not C++ code.
It's more likely that you want to #include
a C++ header file (typically ending in .h
or .hpp
), and link an object file.
You can do this in the Visual C++ compiler, using #pragma comment(lib, "libname")
- and the similarity is somewhat dubious. However you will have to discover any alternatives for your own favourite compiler.
#include
is used for telling the compiler about the functions from a library which you will call in your code, that is to say it includes C++ code. Generally this takes the form of header files which have the function declarations in them.
.a and .so and .o files are compliled code which can be linked into your compiled code using the linker.
Edit: there's an introduction about compiling and linking here
The #include
statement basically just includes other source code into the current file. That being said, a static library is not source code and cannot be included in this manner. Static (and shared) libraries are instead linked into the project after all the compiling is done.
What you have to do is to include a file containing prototypes to the functions you are going to be using. This way the compiler knows it is there and the linker will sort out the rest.
For more information on how to create and link static/shared libraries, check out this page.
It simply doesn't make sense.
You include the library's code at compile time by linking it.
Normally there's a header file for the library you can include.
精彩评论