Compile C++ Code in Windows 7 ("g++" command not recognized) [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm writing a basic C++ program in Windows 7 that I am hoping to compile from itemindiv.cpp, itemindiv.h, item.cpp, item.h, container.cpp, container.h, and main.cpp. I've tried installing g++ and when I type "g++" command line, it doesn't recognize the command. I can't find a simple way to compile these files together, which was easy in command line on a unix system. Is there an easy way to compile this so I can interact with basic input and output (text based)?

Using g++ on windows via the command line is entirely viable through the use of something like MinGW or MinGW64, and you do not need to install Visual Studio to do it. However, it must be configured properly!
Notably, when running something from a command line, it's important to make sure it's fully installed and "on the path". The PATH is essentially a list of locations Windows will look for the program you're trying to run in.
Your first step should be locating g++ on your machine, and I assume in the install directory. This will not only tell you if you if it was installed correctly, but will help us configure the path. Generally, files you can run are going to be located in a /bin folder. In the case of MinGW64, this is located with in the installation directory.
On my machine for example, g++ is located at C:\mingw64\bin\g++.exe, which is where I ended up installing MinGW. You can also force windows to run g++.exe by providing the full path to it in the command line, regardless of if it's on the windows PATH or not. In my case, this may look as follows: C:\mingw64\bin\g++.exe myfile.cpp -o output.exe
If you are able to find the executable but it won't run from CMD/Powershell, this very often means that either the path doesn't include the install directory. Lets fix that.
Putting g++ on the path
Figure out the folder that the application is located in. In my case, this is C:\mingw64\bin\, but the location of g++.exe on your machine may and probably will vary.
Add your directory to the path: This can be done manually as follows, or with the help of a tool like EVEditor. This process is covered in a few other stack overflow answers as well, but I'll go over it quickly here:
In windows 7, right-click on My Computer and click Properties, then click on the advanced tab. In the advanced section, there should be an environment variables button, which should pop up a window titled Environment Variables.
Highlight the path variable, and click edit. The path is made up of semicolon ; delimited entries, and so we can and modify it to include C:\mingw\bin; (or wherever g++ is located for you) at the front - note the addition of the semicolon at the end of the filepath! It's important you do not delete what is already on the path, or this may impact the ability of other programs on your machine to run! In addition, windows searches the path in the order specified: front to back. If you have two folders, both with g++.exe in them, the first one appearing on the path will be used.
Once you've added it to the path, make sure you've restarted CMD/Powershell so your changes to the path are applied!
Note: If you think you added something to the path but it's still not accessible from the command line, you can have windows dump out what it thinks the path is in a given terminal window with echo %PATH%.

You need to install Microsoft Visual Studio and the create a C++ project.
Ensure to select to install Visual C++ modules during the Microsoft Visual Studio installation.

Related

How to compile and run a C++ open source program? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
This question may seem stupid, but as a beginner I did encounter this question when I moved forward, and I couldn’t find any information.
https://upload.cc/i1/2020/12/30/rUEC9s.png
https://upload.cc/i1/2020/12/30/d7Gwbr.png
https://upload.cc/i1/2020/12/30/6vr3lQ.png
This is an open source C++ program, I tried to compile and run it, but it failed
I have the following confusion:
Why the program does not have main.cpp
Update: When asking the first question, I even forgot helloworld.cpp, sorry
How do I compile and run it with CLion
Update: Usually I create a new project. After I create the project, it seems that it can be compiled and run for granted, but I don’t know how to compile and run an existing project (from others).
What do the folders in the first picture usually refer to
What does cmake and CMakeList.txt mean?
This open source program calls opencv, fftw and other libraries. I downloaded the corresponding files on the official website. How should the program call these libraries next?
If I download the library package on the official website, how should I install or configure it; if I install the package using homebrew, does that mean I have already configured it? Or I just finished downloading
I have written some programs in c++ and qt, but I don’t seem to know anything about c++
Finally, there is really nothing in the readme of this project
Your questions are too broad. Generally speaking, the answers would be something like this:
Naming your main file main.cpp is a convention, but is not required. What is required is a main() function (More info here).
You have to configure CLion to open Makefiles. There is a tutorial in CLion's website (Here).
What documents do you refer to?
src: Naming convention to the folder where the source (.cpp) files go.
include: Naming convention where the header (.hpp) files go.
License.txt: Where the software's license is written.
readme.md: Document that gives information about the project.
tests: Files to test the software.
cmake is a tool designed to build and package software (Their website is here). CMakeLists.txt is the file CMake uses to know how to create a Makefile and build the program.
You have to make the system know where the libraries are. You can achieve this by adding them to the project's folder or by adding them to the PATH of your compiler.
If you don't know very much about of C++ you should probably search a good C++ textbook. However, remember that Makefiles and C++ are 2 completely different things.
Most open source programs have build instructions somewhere in the readme.
It is usually best to follow those, even if they require downloading unfamiliar tools.
If the project doesn't have (detailed) build instructions, you should ask the owner, to add (more detailed) build instructions(by for example creating an issue for git-based repositories).

Sending your c++ project [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have coded an app in c++ using the SFML library. I configured it into code blocks to run the program. Let's say I now want to send this app to my friend, what's the best way I can do this so that he doesn't have to go through downloading a lot of stuff to run it?
I am using the MinGW compiler.
Create an installer or package. For example; On RedHat Linux you'd want to create a RPM package. On Windows you want to create a MSI file. Whatever you do, the package you create should bundle up everything your application needs to run and put it into the correct location(s) on the target system. This includes your executable but also any libraries you use (including your compilers runtime libraries).
In most cases just shipping your .exe and all of its dependancies is enough.
In some cases you may also need to ship other files needed to run the application like configuration files, images, icons...
You can use copypedeps with the -r flag from https://github.com/brechtsanders/pedeps to copy your .exe along with its dependancy .dll files into an empty folder.
Then you can just zip everything in that folder and send it to somebody who can just unzip it an run the .exe.
Or you can make a proper installer to distribute the same files.
Your program needs some .dlls to run: some are the system ones, some are shipped with the compiler, and some come from the libraries you use (SFML). You need to ship all those .dlls (except the system ones) with your .exe, and they should be in the same directory.
It doesn't really matter if you make a proper installer or send your friend a zip archive. (If it's an archive, they might have to manually extract it before running the .exe.)
The question is how to figure out which .dlls to ship. There are several approaches:
Open the console, cd to where your .exe is, do set PATH= and try running the executable by typing its name. Since the compiler installation is no longer in the PATH, it shouldn't see the .dlls in there, and it should complain about them being missing. After you provide one .dll, it will ask for the next one.
A more civilized approach is to use a tool like ntdll to list all .dlls your app uses. Then copy them, ignoring the system ones (located in C:\Windows or subdirectories).
Note that both approaches rely on there being no extraneous .dlls in C:\Windows or subdirectories; some poorly written installers like to put their own .dlls in there. To check for that, make a list of all .dlls that come with your compiler (they should be in the same directory as the gcc.exe), and the ones that come from your libraries (SFML). Then look for the .dlls with the same name in C:\Windows and subdirectories, and if you find any, remove them.

Can I convert an `a.out` file into an "executable" - like in C/C++ (on Linux!)? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I remember using Visual Studio on Windows for C/C++, which created a name.exe file for every console application I created. Can I make that on Linux?
I don't want to open it with ./a.out. I would like to know if I can make it just like on Windows, double click on the file and a console is popping out.
a.out is an executable... rename it. If you want gcc to specify the executable name, use the "-o" compiler option, for example:
gcc file.c -o exename
If I understand correctly, you have a program that requires a terminal. When you click on the program in a file manager, it runs the program, but since it doesn't open a terminal, the output goes to some log file. You want to open a terminal and run your program from the file manager.
Under Linux, this is done with a .desktop file. As with many things, there is a good tutorial in the Arch Wiki. This is a separate file from the executable: Linux executables don't have a special case for “console” applications like Windows does. Once and for all, create a .desktop file with the path to your program. You can put the .desktop file in the same directory or a different one as you like. The .desktop file can be something like this:
[Desktop Entry]
Type=Application
Version=1.0
Name=Run a.out
Exec=./a.out
Terminal=True
Give the .desktop execute permissions.
Yes, you can. A a.out in Linux is just like name.exe in Windows. In a Unix/Linux environment, a C or C++ compiler by default make the EXE file as a.out which is a EXE file only. In Linux, just compile your code like below to make an EXE as per your requirement:
gcc your_cpp_file.cpp -o name.exe

How to save date in a console application c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
When you make a C++ console application on VisualStudio for example, when you use your application and you quit it, I think the data is lost is that right? Is there a way to not lose the data and make an .exe from the console project to have a program that you can open, close, open and modify the data?
When you use your application in Visual Studio it first creates an executable file, an exe file. The C++ file is compiled and linked. The compiling and linking is called a build.
At the bottom of Visual Studio you will see an "Output" window. Errors will appear there if there are any. If there are not errors then you will see a line similar to the following.
1> SO36972615.vcxproj -> c:\users\sam\documents\visual studio 2015\Projects\SO36972615\Debug\SO36972615.exe
Here, "SO36972615" is the project name. The project is at:
c:\users\sam\documents\visual studio 2015\Projects\SO36972615
The project files are in that directory. There is a "Debug" subdirectory with an exe file in it, SO36972615.exe. You can execute that file outside of VS. You can also copy it to some other place in your system.
To use your program in another system, you will probably need to do what is called a Release build. You need to learn about that too. If you do a Release build then you might be able to just copy your exe file to another system.
You probably need a setup system to install your program into another system. A setup is also called a deployment and programmers often say they need to deploy their software. Learning how to deploy (create a setup for) your program will take time but that is how you would be able to use your program in other systems.

Is there an equivalent of Make on Windows? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I develop on Windows, and I'd like to use beanstalkd. It's only available as a tarball, and I was just wondering if there is some way to easily build it like you can in Linux? I found some ports of gnu make for Windows, but they don't seem to be working. Are the source distributions somehow specific to Linux?
When I try to use mingw32-make it says "Nothing to be done for file". TBH I wasn't sure what to run it on, so I tried the tarball, the directory, and Makefile.in and Makefile.am. They all say the same thing.
Make is available in cygwin, which you can install make via the installer.
The package is called "make", which is under "Devel" category.
I found some ports of gnu make for
Windows, but they don't seem to be
working.
Here are a few ports of GNU tools to Windows:
GnuWin32 - http://gnuwin32.sourceforge.net/summary.html
Gnu Tools for NT - http://www.devhood.com/Tools/tool_details.aspx?tool_id=3
GNU Utilities for Win32 - http://unxutils.sourceforge.net/
I am pretty sure I have used some of the utilities from the unxutils port without problems.
I would also look into using msys with mingw (it also can be found at http://mingw.org) I could try to explain it but I think the description from their page works better
MSYS: A Minimal SYStem providing a POSIX compatible Bourne shell environment, with a small collection of UNIX command line tools. Primarily developed as a means to execute the configure scripts and Makefiles used to build Open Source software, but also useful as a general purpose command line interface to replace Windows cmd.exe.
One bonus of using msys over cygwin is it builds native windows applications rather than having to rely on the cygwin compatibility layer
Most unix source packages require you to run "configure", which reads some info about your system and builds the Makefile - although in the early days of X11, some packages used "xmkmf" to build Makefiles out of IMakefiles. Only after thats done can you run "make" and possibly "make install". From the sound of it, you don't have a Makefile, only the Makefile.in (which is input to configure).
Cygwin is nice, as the previous answer indicated, but it includes a lot more than just make.
I used to use NMake on Windows to build Perl modules. Check it out:
http://johnbokma.com/perl/make-for-windows.html
That's useful for Perl. Looks like there's a general GNU port, too:
http://gnuwin32.sourceforge.net/packages/make.htm
Cygwin and mingw come to mind.
MSVC includes nmake which kind of works on regular makefiles with some tweaking.
The make utility expects to use a file named Makefile. If you just type make, it will find that file automatically. If the makefile has some other name, use the -f option. If you just give the file name without -f, then make will interpret it as the target that it should figure out how to make.
A lot of tools that only come as source assume that you'll use Visual C++ to build on Windows, even if they assume you'll use G++ everywhere else. Look for a Visual C++ makefile; it's usually named Makefile.mak. Then run nmake.
But if you only have files named Makefile.in and Makefile.am, then you don't yet have a makable environment. Makefile.in is one of the inputs to the configure script, which will construct the real makefile and maybe a header or two that are specific to your environment, based on tests that configure runs.
In the end, the package you've downloaded might not really be compilable on Windows. Even under Cygwin, you can expect to have to make a few changes to the source code if it hasn't been written with Windows in mind.
Makefile.in will contain the basics of the final makefile. Back before I knew what I was supposed to do, I simply renamed Makefile.in to Makefile and got pretty far. You can try using that file as a starting point for constructing a real Windows makefile, for whichever compiler target you choose. It will take patience; just keep following the compiler messages until you don't see any more. (And then comes the linker. Hope you don't need too many other libraries!)
Concerning the alternatives, check out this link. As far as your problem with make, you'll have to be a little more specific about the non-working part. What doesn't work, how does it manifest, what error it gives and such.
Let someone else do the hard work. Here's a precompiled beanstalkd 1.4.6 exe.
Decompress the tarball, cd into its topmost directory and type 'make'. Make will pick up the Makefile automatically.