0

So, I'm trying to compile a basic c++ program, but when I run it on other computers, I get a "missing DLL" error. I looked it up and apparently adding -static-libstdc++ can fix the issue without having to add DLLs in the directory. I'm wondering how you add linker options when compiling. Do you add linker options along with the compiler options like this?

g++ -i some/program.cpp -o some/program.exe -(linker options here)

thanks to an amazing person, he solved my issue! What you do is add -static to the compiler options.

  • Have you seen https://stackoverflow.com/questions/6141147/how-do-i-include-a-path-to-libraries-in-g ? – h0r53 May 06 '21 at 17:02
  • @h0r53 I'm sorry, but I don't really understand what's going on in that post. All I want to know is how to add linker options. –  May 06 '21 at 17:03
  • Can you provide the name, or at least an example name, for the file/s you want to statically link? – h0r53 May 06 '21 at 17:09
  • 2
    This one is `g++ -static-libstdc++ some/program.cpp -o some/program.exe` But it only links in the C++ standard library. You'll probably want `g++ -static some/program.cpp -o some/program.exe` to drag in C, C++, and support – user4581301 May 06 '21 at 17:30
  • @user4581301 thank you so much! –  May 06 '21 at 21:45

1 Answers1

0

If you are on Windows, then you can add the following into your code

#pragma comment("lib", "dll-file-without-.dll-file-extension")

Or with GCC you can compile with

g++ -i some/program.cpp -o some/program.exe -L<directory-to-dll> -l<dll-file-without-.dll-file-extension>
YG-cpu
  • 37
  • 3
  • I think I see where you are trying to go with the GCC example, but you don't quite get there. In order to understand that part of the answer you already have to know what to do. – user4581301 May 06 '21 at 17:23