So for school I made a simple game using the SDL graphics library, and did it in Visual Studios C++. However, I must turn in the source code so that it will compile through Cygwin. I have tried so very hard to figure out the proper way to link everything, but just cannot do it.
Normally I would compile a normal .cpp file through Cygwin something like this:
g++ -W -Wall -pedantic -o test test.cpp
So my questions are:
What is the proper command line command in order to compile (with g++) SDL source code.
Also, how should I folder all the files so that when my instructor gets it, he can run the exact same command as I do?
Should I have the entire SDL library inside with the source code folder? I would like everything grouped so that all he has to do is run the proper command.
The simpler the better :)
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 just beginning to experiment with C/C++ and SQLite, and installed the minGW-w64 compiler and was able to get the little "Hello, world." code to compile to an .exe file and run it.
Then I added the sqlite3.c amalgamation file to the directory and attempted to compile it with the helloworld.c file, and the first result was many, many rows of errors and warnings, it appears because I used g++ instead of gcc.
I have two very basic questions.
Is it correct to always use the sqlite3.c amalgamation file in this manner, compiling it along with the rest of the code, even though it is a rather large file. The SQLite web site states, "The use of the amalgamation is recommended for all applications" and "makes [them] run faster."
The .exe file was 53kb for hello world compiled alone and 1,015kb for the combination even though no SQLite statements were used.
Why did using g++ generate the large error list and gcc did not generate any? I realize that g++ is for c and c++ and sqlite3 is c. Does this mean that a c++ file and sqlite3.c cannot be compiled together?
Thank you.
Yes, bundling sqlite like that is intended behavior.
You can compile sqlite3.c with a C compiler first and link the result into a binary:
gcc -O2 -c sqlite3.c
g++ -O2 sqlite3.o myapp.cpp -o myapp.exe
I strongly suggest automating this project with a simple makefile or Cmake.
I used to code on Linux and installed the Eigen library. I build my code with the g++ compiler. I want to code on Windows (8.1, 64bits) but plenty of errors (at least plenty of lines in the cmd) appear when I am compiling. Where is the problem ? Why does Windows find all these troubles ?
I created a makefile (cf. next paragraph) on Linux and everything compiled without issues. Then, I moved to Windows. I copied and paste the whole folder containing .cpp, .h, .cc files and the Eigen library, and I installed the g++ compiler through MinGW. But when I type "mingw32-make", tens of lines appear.
I use Atom as a text editor.
Makefile :
run: main.cc
mingw32-g++ -Wall -g -fcheck-new -std=c++11 -I C:\Users\Utilisateur\Documents\TESTC++\eigen-eigen-b9cd8366d4e8\Eigen -o run Laplacian1D.cpp main.cc
clean :
rm -rf *.o *.mod *.vtk run
I expect not to have as many lines, and I do not know what they mean (most of them concern the Eigen library, as you can see in the screenshots).
Note that I have screenshoted the first part of the cmd, but if you want me to focus on a special part do not hesitate.
I thank you very much for your understanding and your help,
Sincerely,
Jacataa cmd screenshot
I finally find my (awful) mistake...as dumb as it is simplistic.
In fact, I have used the Eigen Library downloaded with Linux, and as both OS are different, that is why there were all of these "errors" displayed.
By downloading this library on Windows, it finally works now.
I thank you for your previous answers, and if someone could answer this last question that Jesper Juhl emitted : why does my program run slowly ? (I use a i5-4690, maybe its existence is the problem) then I would be very thankful.
Thank you in advance,
Sincerely,
Jacataa
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 tired searching in internet.
I created a klient-serwer program, which shut down computer just by their IP's on specific port.I made whole thing in C, everything works perfectly, i'm compiling my project using gcc with -Wall option and I've got a clear results.
But I had to create GUI so i decided to use QT Creator IDE, I transfered code from C into C++ and i made GUI. Program works but I have to compile this using g++ with -Wall option.
Thing is, I cannot compile anything.
g++ my_project.cpp -o mypro -Wall
ERROR: fatal error: QMainWindow: directory don't exist (in my native language)
compilation terminated
(same with other source files)
Any ideas?
It's propably very easy, but believe me, I want to compile this and go to sleep. Cheers
Why don't you use qmake? First, you can edit your *.pro file and add any compiler flags you wish (see Mitch's comment). Then, if you execute qmake and then make, it will show you a sequence of compilation commands with proper flags, linker and include paths and so on. After that you can just reproduce that commands manually if your teacher wants so.
The error shows that the compiler is trying to open QMainWindow as if it was a directory (if the translation is correct) or at least failing to locate where the include files for Qt are. You probably need to provide some -I option to hint the compiler as to where the Qt headers are, and make sure that the #include directives are correct in your code.