简体   繁体   中英

static library doesn't contain macro

I have a static library project (written in C language) and another sample project (written in C language) under Visual Studio 2015. I can use the functions located at the library in the sample project without any problem. My problem is that I have a macro in one of the header files in the static library project and I can't see (or use) this macro in the sample project. I receive this error: "unresolved external symbol ADD1 referenced in function main". How can I use this macro in the sample project?

Note: I use the library file in the sample project thanks to this pragma this pragma: #pragma comment(lib, "mylib.lib")

I do not want to include any of the header files of the static library project. They are not supposed to be seen by other projects.

I think there is some confusion.


To make use of any library, you must know about its functions, datatypes (eg: enum , struct , typedef ), macros, etc... This all comes together to form the library's 'API'.

Most libraries (not all) will have some internal headers. You are correct, these are not supposed to be seen by other projects, and will be used strictly internally.

All libraries will have some 'public' headers that define their API. A code base Without a public API is either useless, or actually an application that stands on its own.

Include your header with the #include directive, not with some pragma.

A header should be written so that it is the public interface to your library, even if the library code itself may not be open. Either the macro is public and can then be declared in the header, or it is not public in which case you should encapsulate it inside the library.

If the library code is pre-compiled and delivered as a binary, either declare it in a C file or in a H file that the caller does not have access to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM