In the .h file of my program, the structure is initialized.
I need to use a static library instead. I compiled a static library in Visual Studio, where I call only the header. The problem is that I can not connect it to my program. I tried to do this by adding this: (#pragma comment ( lib, "MathFuncsLib.lib" )) to the Studio properties (Linker -> Input -> Additional dependencies), but it did not help me.
I get an error:

Error LNK1104 cannot open the file "#pragma comment (lib, \ MathFuncsLib.lib \) .obj


If you add only MathFuncsLib.lib there, then the compilation crashes, but not because of the library's calling curve, but because of the lack of a definition of the structure.
Do not tell me how to fix this? Thank.

  • compiles fine, but nothing happens - Excuse me, what do you expect? What is going to happen? - Harry
  • Made a reservation. Connection stat. libraries should replace the header call. - tank0412
  • A compilation crashes, but not because of the library's calling curve, but because of the lack of a structure definition. - tank0412
  • one
    You, in my opinion, are somewhat confused. A bit simplified - in the header file are all sorts of declarations, the same types of structures, etc. And in the library in the first place - the body of the functions, well, global variables. When you include <stdio.h>, then you take an ad some printf from there, but its code is from the corresponding library. And one is not replaced by another. You still need a header file that describes data types, function declarations, etc. And in the library there is a ready- compiled code of these functions for working with these types. - Harry
  • I understand it. But the task states this: Supplement the implementation of the laboratory work in such a way that the description of data structures and functionality from the subject area is in a statically linked library. - tank0412

1 answer 1

  • First, connecting a library cannot replace the inclusion of a header file. It is necessary and that, and that. That is, there can be no talk of any “using a static library instead ”.

  • Secondly, the library cannot contain "only a header". A traditional header does not contain an object code or any material entities at all. Therefore, the library can not be made from it.

  • Thirdly, when connecting libraries via #pragma comment , this #pragma comment(lib, "MathFuncsLib.lib") should not be added to the "Studio properties" (where did you get this idea?), But directly to the source code of your program . That's the whole point of #pragma comment .

    But usually the libraries are connected via the linker settings, and not through the #pragma comment . If you want to go along this traditional path, then this is done through the properties of the project (not the Studio, but your project). In the linker settings you just need to add MathFuncsLib.lib .

    Of course, it is also necessary that the linker know where to look for this MathFuncsLib.lib , i.e. you must either put MathFuncsLib.lib in the right place, or set the correct paths in the linker settings, or specify the full path to MathFuncsLib.lib .