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.
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 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.
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 have got my first project for this semester and I have been asked to submit it with a makefile. The literature available on the internet is a bit overwhelming and combined with my laziness, I came to stackoverflow for simple answers. I have found this answer by Brendan Long as a good place to start with.
The example he gives is:
all: a3driver.o
g++ -o a3driver a3driver.o
a3driver.o: a3driver.cpp
g++ -c a3driver.cpp
which i understand. This looks exactly like the make files I have seen on a Unix system and which i used to compile c++ files(only used, did not need to understand).
Then i search further and an answer to this question suggests using CMake which is completely different from the code I have pasted above.
So my question at this stage is which direction should i take? Should I learn about the CMake or the GNUMake? I only intend to work on C++ files for now.
Only you can answer this question because it depends heavily on your needs. Cmake is a "build control file generator", not a build control program. It doesn't actually build code: instead it will create a makefile, or a Visual Studio / Xcode / Eclipse project file, etc. You then use that build program (make, Visual Studio, XCode, Eclipse) to actually build the code.
Cmake is good if you need to support all those different types of builds across all those different architectures using their native build environments. If you're happy to use make on whichever architecture you need to build on (GNU make runs on all of those as well and all those IDEs except possibly Visual Studio have good integration with native make) then using make directly is fine. GNU make has lots of advanced features which make it very flexible.
I don't really agree with esseks assessment of the autotools although I know it's a very common opinion. Also note that automake itself does not use unusual, verbose syntax: automake files are just makefiles. However they have to be processed, and autoconf is how that's done... autoconf is more obscure although not as bad as people make it out to be, depending on your needs. This isn't the place for that discussion however.
I personally find cmake format even more annoying and strange than autotools, and it doesn't meet my needs in many ways (for example it's support for cross-compilation is not as good as autotools'). However I have to say its ability to generate native project files is really excellent--if you need it.
If you need a really really dead simple makefile for compiling one or few files only, then you are done with:
compile:
g++ myprogram.cpp -o myprogram
(note that lines must be indented with tab, not spaces).
If you need flexibility, you are on the right path with CMake. I suggest you to explore CMake, starting from their good tutorial or a simple example -- as the basics are simpler to undestand from code rather than learn from manual.
My personal opionion is to avoid GNU Automake (colloquially known as Autohell) because of the unusual, verbose syntax that sometimes scares beginners and tricks more experienced users.
EDIT: CMake is not used to compile, rather, it can generate makefiles for you, starting from a synthetic description of the project (where are the files to be compiled? What libraries are required? etc.). And it does this by checking for libraries, identifying compiler and carrying out other sanity check you would need to code by yourself otherwise.
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.