I have been toying around with javidx9's olcPixelGameEngine (a single-header game prototyping engine) for a while now, but I have been experiencing some problems related to the necessary libraries for compiling the code. The header file offers many #pragma comment for telling Visual Studio what libraries to link, but since I can't use Visual Studio (my computer is very old and can't run it well), I tried compiling by hand, linking each library. The resulting command ended up being something like g++ .\main.cpp -std=c++17 -luser32 -lgdi32 -lopengl32 -lgdiplus -lShlwapi -lstdc++fs, which is a tad too big for my liking. Is there a way to simplify this entire command into something reusable for other .cpp files? I thought of make files, but since I use mostly Windows, I don't know how to use them. Being able to link automatically, or just mixing all those flags into a single command would be very helpful.
I'm currently using MinGW, installed with MSYS2, for compiling, if that can help.
Related
I have changed my IDE's from DEV-C++ to Visual Studio code, but now, I cannot add my opengl addons when compiling the program. DEV-C++ gives you the posibilty to add addons to the compiler call, for example I used -lglu32 -lglut32 -lopengl32 for my opengl programms making the compiler call look something like this: gcc.exe "C:\Users\Main\Downloads\C\OpenGL Base\main.c" -o "C:\Users\Main\Downloads\C\OpenGL Base\main.exe" -lglu32 -lglut32 -lopengl32 -std=c99 -I"C:\MinGW\include" -L"C:\MinGW\lib" -static-libstdc++ -static-libgcc however I do not know how to recreate this automatically in VS Code without having to rename the address for every different program I compile.
First, visual studio code is just a code editor with some extra features like an embedded command line terminal or extension that can be installed, providing extra functionality. This means that there are many ways to build a C/C++ application, e.g. by writing your own scripts that you run via the terminal, or by using build systems like Make or others via terminal or an installed extension. You probably want to take a look at the C/C++ extensions available for visual studio code. There are already other stack overflow articles already covering this topic:
How do I set up Visual Studio Code to compile C++ code?
If you just want to use the same flags for building different applications, you might want to just put the command into a script which uses the current directory (if this is what you meant by address). That way the script would work for different projects/applications located in different directories.
I'm having a C++ Project in Visual Studio 2017 which uses curl. It compiles fine on a linux machine. But i think my procedure is not efficient. Im just copying my source files to the linux machine and run
g++ one.cpp two.cpp etc.cpp -lcurl
or even
g++ *.cpp -lcurl -o output
Is there something to do this a "cool" way? Like cmake or something (sorry im not into this). An Example would be really helpful
Your options range wildly from:
Just keep doing what you're doing
Wrap that command in a shell script so you don't have to keep typing it
Make a Makefile to auto-generate that command
Use CMake to auto-generate the Makefile (or automake or something else)
Use an IDE (examples for various platforms: Eclipse, Xcode, Visual Studio) to fully manage the project for you, including build rules/commands — Visual Studio Code in particular may be of interest here
It is completely up to you what you pick.
Personally, in your situation, right now I'd just throw together a Makefile and be done with it, until your needs become more complex.
Whichever of the latter 3 options you pick, there are abundant examples online and in your book already.
I would say, please don't use a really complicated solution to solve a simple problem just because it's "cool", because that's not what cool is.
I'm fairly new to C++ (a long time Lisp programmer) and am trying to compile some of the examples for dlib on Windows using MinGW. I added dlib into the PATH. I then call g++ timer_ex.cpp from the examples directory. But I get a lot of error messages.
Short of using Visual Studio, what's the best way of compiling dlib examples on Windows?
Adding the folder to PATH usually doesn't work out well for me. Instead, try this command. I just compiled the example with it without error:
g++ timer_ex.cpp ..\dlib\all\source.cpp -I.. -luser32 -lws2_32 -lgdi32 -lcomctl32 -limm32
The somewhat cryptic -I.. adds the folder one level up to the include search path. This is the right thing to do assuming your haven't changed the folder layout. But in general this is the easiest way to add something to the compiler's include search path.
You also probably want to add the -O3 option which will tell gcc to produce optimized executables. Generally this makes the resulting application a lot faster, especially if you are doing heavy numerical work.
As an aside, you should consider installing CMake. It's a convenient tool which sets up a project like this for you. It works on Windows, Linux, Mac OS and many other platforms. To use it to compile the dlib example programs you would just have to say cmake . from within the example folder and then make. There is also a free version of visual studio which is quite nice, and as a bonus cmake can automatically create the project files for you.
I'm trying to compile my program on Windows via Cygwin with the compilation command:
g++ ping.cpp -I./include -L./lib -lchartdir50
I'm using an API called ChartDirector which draws charts for me. I've never linked libraries this way before (usually I do it through Visual Studio), so I’m a little new to this. I've got a really large list of errors, so I won't list them all, but I’ll list one just to clarify the type of linker errors I’m getting:
(.text$_ZN9BaseChartD1Ev[BaseChart::~BaseChart()]+0x4f): undefined reference to '_CBaseChart_destroy'
All of these are undefined reference to 'xxx' errors.
I've got a bunch of header files in ./include and a library called chartdir50.lib in ./lib.
What’s wrong with my compilation line?
I never use that library before, but when I googled it, I noticed that other people trying like -lchartdir instead of -lchartdir50, so you should give it a try.
I am not sure, but .lib have been compiled with Visual C++?
If yes, I don't think it's compatible with GCC. You have to compile the library with GCC/G++ and use that file or to use a compatible binary if you don't have access to the source.
Hmm... that’s odd. I'm using a 64-bit system, but for some reason I tried it with the 32-bit library and it compiled. Thanks!
I assume that library was also created with GCC.
As far as I know, .lib is a static library, so you don't have to point it with the -l compiler switch.
Just use it as another file on the command line, like
g++ ping.cpp -I./include -L./lib {path to lib here}/chartdir50.lib
Where can I find an writeup that shows me how to set up a tool chain for WxWidgets (C++) on linux/ubunto and/or OS X.
I downloaded, compiled & installed WxWidgets both on linux and OS X, compiled and tried the samples, but seem to be stuck setting up a compile environment in my own home directory.
DialogBlocks from http://www.dialogblocks.com looked promising, but it insists on recompiling WxWidgets again and again .. must be something about it I don't understand.
Writing code from scratch seems to fail due to a lack of paths to libraries, tools or whatnot .. again a lack og understanding on my part, I am sure.
So, can anyone point me to a tool chain setup, that has more than the bare minimum of instructions and fills in some of the "why" instead of only the minimal "what".
Like all C/C++ programs, the compiler has to know in what directories to look for include files, and the linker has to know what libraries it should link to.
The WxWidgets package, if installed correctly, includes the program wx-config. This can be used while compiling and linking, like so:
g++ $(wx-config --cxxflags) -c my_prog.cpp
g++ my_prog.o $(wx-config --libs) -o my_prog
I've found these two pages to be of help when setting up wxWidgets for Eclipse and MinGW.