Hello!

I often see libraries in which there is only a declaration of functions, and the declaration is hidden somewhere. For example, there is a library that declares a class. Only where it is declared is not visible. How it's done?

  • Well, if by declaration you understand the description in * .hpp, then the implementation should be in the * .cpp file. That is, if the library is declared in the file Foo.h? then the implementation is in the file Foo.cpp or in some dll, which one to look at the declaration. - abalckin
  • Well, there is no .cpp file. There is only some .a - user26699

1 answer 1

Oh, I found: http://www.techytalk.info/c-cplusplus-library-programming-on-linux-part-one-static-libraries/comment-page-1/ . Is it only cross-platform?

#ifndef EGE_H #define EGE_H void doStuff(); #endif //EGE_H 

This is how it turns out. But the makefile:

 makelib: g++ -Wall -I ./include/ -c ./src/*.cpp ar rcs ./lib/libEGE.a ./*.o all: g++ -I ./include/ -L ./lib/ -lEGE -o ege_test main.cpp 
  • Well, can, show a slice of your hpp file? - abalckin
  • @abalckin, updated - user26699
  • This is the native way to build a static library under nix (i.e., on Unix and Linux). For Windows out of the box, this will not work, you need to install and configure a special package of nix utilities - MinGW (which is worth or with which only a small number of Windows developers are willing to deal with). Therefore, the correct way to build for Unix and Linux as you described above, and for Windows it is better to use the tools provided by VisualStudio. - Xmaster
  • @Xmaster, IMHO, a project for VS is too bold, a bat file for compiling with studio tools will be quite enough. - insolor
  • @insolor, will advise here. If we are seriously developing a library, it is better to use a cross-platform build system, like [CMake] [1] or [GYP] [2]. [1]: cmake.org [2]: code.google.com/p/gyp - dzhioev