cvisual-studiomacrosstatic-libraries

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")


Solution

  • 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.