0

I'm trying to make function which will return version from FileVersionInfo, so far i built funtcion, but i have issue when i want to include version.lib

#pragma comment(lib, "version.lib")

I have tried to link, libversion.a, something like this

#pragma comment(lib, "libversion.a")

but, again compiler was returning error like first time

Pragma ignoring comment [-Werror=unknown-pragmas]

I have tried, many combinations from internet, i cant even remember all of them. I'm using MinGW compiler. Thanks for your time i appricitate it :)

gmijo47
  • 59
  • 9
  • 1
    It doesn't look like GCC supports that particular pragma. – Nathan Pierson Sep 19 '21 at 17:51
  • If it doesn't support it is there any alternative? – gmijo47 Sep 19 '21 at 17:57
  • This pragma to link libraries from C++ source code is only supported (I think) by MSVC. – prapin Sep 19 '21 at 17:58
  • 2
    Specify the library you want to link against with the `-l` flag. [See here](https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html). You may need to use the `-L` flag to inform the linker about directories it needs to search for libraries. – Nathan Pierson Sep 19 '21 at 17:58
  • 1
    Does this answer your question? [#pragma comment(lib, "xxx.lib") equivalent under Linux?](https://stackoverflow.com/questions/1685206/pragma-commentlib-xxx-lib-equivalent-under-linux) (The question asks about Linux but essentially it seems like it's about a GCC equivalent) – mediocrevegetable1 Sep 19 '21 at 18:02
  • 1
    Also note that unknown-pragmas is only a warning, but it's being promoted to an error by `-Werror`. You can downgrade that diagnostic back down to a warning with `-Wno-error=unknown-pragmas`, or silence it altogether with `-Wno-unknown-pragmas`. – Brian61354270 Sep 19 '21 at 18:03
  • @NathanPierson did you mean like this '#pragma comment(lib, -l "libversion.a")' or something else if im not right can you provide me simple example – gmijo47 Sep 19 '21 at 18:18
  • No, I meant that you need to use those as command-line arguments passed to your invocation of the linker, not in the source code at all. – Nathan Pierson Sep 19 '21 at 18:20
  • Alright i'll give it a try – gmijo47 Sep 19 '21 at 18:21
  • @NathanPierson what i tried is this "mingw32-make -j8 install -l libversion.a" in my build and install batch file, still same, also i tried to add -L and full path to libversion.a, still same (im stuck for like 2 days), also i may be that im doing something wrong, or i maybe add sometong to my CMakeLists.txt – gmijo47 Sep 19 '21 at 18:31
  • What are the contents of your makefile? – Nathan Pierson Sep 19 '21 at 18:34
  • @NathanPierson https://pastebin.com/DRZq8Gqa CMakeList.txt pass: stack, (edited, wrong link) – gmijo47 Sep 19 '21 at 18:39
  • Okay. I'm not familiar with CMake. You probably need to edit the sections titled `#Link libraries` or `#Library`, though. Does [this question](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) help? – Nathan Pierson Sep 19 '21 at 18:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/237262/discussion-between-gmijo47-and-nathan-pierson). @NathanPierson – gmijo47 Sep 19 '21 at 19:06
  • 1
    @prapin "*This pragma to link libraries from C++ source code is only supported (I think) by MSVC*" - MSVC is not the only compiler that supports this. C++Builder supports it, too. – Remy Lebeau Sep 19 '21 at 19:55

1 Answers1

1

"This pragma to link libraries from C++ source code is only supported by MSVC"

Switched compiler from gcc/g++ to MSVC, that's only solution :(

gmijo47
  • 59
  • 9