C++ is one of the simplest programming languages that just about anyone can pick up and understand. It’s also hugely popular with software developers due to its speed and efficiency, making it a great choice for system software.
However, just like all other programming languages, C++ can also be difficult at times and random bugs and glitches are usually the order of the day. In this article, we’re taking a look at the “error adding symbols: DSO missing from command line” issue in C++ and giving you three ways to fix the problem.
Also read: Python vs Java vs C/C++: Key differences and Pros-Cons
Use the right compile syntax
One very common reason why you’re seeing the error is that you’re mentioning the required libraries on the command line before the object files are compiled.
Keep in mind that linking is based on the order of the specified modules. Symbols are requested first and later linked in from their respective libraries. This means that you have to specify modules that use said libraries first. A general syntax would be as follows.
gcc module1 module2 -library1 -library2
Sometimes you might even have to specify the same library multiple times, especially in the case of circular dependencies.
gcc module1 module2 -library1 -library2 -library3
Try switching the library order
This is an extension of the previous solution, but just as it’s important to mention the modules before the libraries, it’s also important to have the modules and their corresponding libraries in the right order.
Double-check your compile command to see if the modules and libraries are properly matched. If they aren’t you can try swapping around libraries until your compile goes through.
Check your compilation flags
Sometimes the absence of some essential compilation options depending on what modules and libraries you’re compiling can also cause this error. This can be caused by performance issues as well. For example, sometimes adding the -lpthread option to the compiler command can make the error go away. Adding -redundant might also help in addition to the aforementioned flag.
Also read: Wslregisterdistribution failed with error 0x800701bc: 3 Fixes