I have used unordered_map in my c++ program. I complied program successfully by using :
g++ -std=c++0x source.cpp
But after that i have entered source to run program but prompt show me that source is not internal or external command.
Default output filename is a.out (a.exe on Windows)
Use -o option to specify file name, like this:
g++ -std=c++0x source.cpp -o source
Related
I like using both Linux and Windows for my C and C++ coding and I prefer using the command line to compile my programs. I can run make on Linux, which is fine. But on Windows, now that I'm working with classes and have to compile multiple files, I find it a chore to type in several g++ commands to compile the class and main object files.
I was wondering if there's a way to get a CMD batch file or PowerShell script to just execute the commands one after the other?
Something like this:
g++ -c Area.cpp -o Area.o
g++ -c Convert.cpp -o Convert.o
g++ -c Calculate.cpp -o Calculate.o
g++ -c multi_menu_functions.cpp -o multi_menu_functions.o
g++ -c main.cpp -o main.o
g++ -Wall main.o Area.o Calculate.o Convert.o multi_menu_functions.o -o main
...Something dead simple and easy.
Just write the commands in a file with extension .bat and you can just start that file. You can turn off outputting the commands while execution of the batch file by starting the file with the line #echo off.
Or better yet: Just get make for windows and use that one.
I figured out the issue of why the g++ commands wouldn't work as is: somehow the laptop I was using didn't grant me the correct permissions. At a guess I tried the full path name for g++.exe and it worked. I reconfigured some things and now it works with the commands as listed.
On a side note; I did get gnumake and minGW make working as well. Since these can run my Linux makefiles I'll use these as well.
I have a suite of Windows programs that up to now I have built under msys, one of which uses libxml2. I am currently trying to switch to building them under msys2 and the latter one is hitting a problem. My updated Makefile includes this:
CFLAGS += -I/mingw32/include/libxml2
$(BINDIR)/%.o: %.c
#-$(MKDIR) $(BINDIR)
$(CC) $(CFLAGS) -c $*.c -o $#
But when I run make (mingw32-make) the compile fails as follows:
[csv-gen]: mingw32-make
gcc -std=c99 -Werror -Wall -D_XOPEN_SOURCE -O -I/mingw32/include/libxml2 -c xmlParse.c -o ../../bin/Win32/csv-gen/xmlParse.o
xmlParse.c:36:27: fatal error: libxml/parser.h: No such file or directory
#include "libxml/parser.h"
^
compilation terminated.
Makefile:66: recipe for target '../../bin/Win32/csv-gen/xmlParse.o' failed
mingw32-make: *** [../../bin/Win32/csv-gen/xmlParse.o] Error 1
Yet that libxml/parser.h file does exist under the /mingw32/include/libxml2 path given by the -I option:
[csv-gen]: ls /mingw32/include/libxml2/libxml/parser.h
/mingw32/include/libxml2/libxml/parser.h
And the strange thing is that if I run the exact same gcc command directly from the msys bash shell (copying and pasting it from the make output above) then it compiles fine with no errors.
And I have the exact same problem with the link phase where it doesn't find the libxml2.a library in the path given to gcc by -L/mingw32/lib, and again I run the gcc link command directly from the shell and it works fine.
So why would gcc's -I/mingw32/include/libxml2 and -L/mingw32/lib options not work when run via mingw32-make yet the exact same options work fine on calling gcc directly from the shell?
I did try making the paths explicit Windows paths (d:/msys64/mingw32/...) and also tried quoting them, to no avail.
It turned out that the answer was to use explicit Windows paths, which as I said above I had tried, but when I tried again it worked so I must have previously made some mistake doing that. I found this by using the output from pkg-config which gives:
[csv-gen]: pkg-config --cflags libxml-2.0
-ID:/msys64/mingw32/include/libxml2
So apparently the problem is that mingw32-make doesn't fully understand the msys filing system, or at least not /mingw32 and /mingw64 paths in it.
I am writing C and C++ code on Linux OS and I am using GCC. After finishing my code, I would like to generate an ELF file. I just can generate "a.out" file and I don't need it. How can I get ELF file ? ELF file occurs as a result of what ? or Is it possible to generate this file with this program ?
The compiler (i.e. gcc or g++) will invoke the linker (ld) which produces an ELF executable.
In practice, you will use a builder program (like make) to drive gcc commands. See this answer.
The default output file for gcc is still named a.out (for historical reasons) but is an ELF file. And you really want to ask gcc to output an executable with a more fancy name.
Simple example, you code a single-file hello-world.c program. You can compile it with e.g.
gcc -Wall -g hello-world.c -o hello-world-bin
(order of arguments to gcc matters a lot!)
and the produced hello-world-bin is an ELF executable. Check with
file hello-world-bin
then run it with
./hello-world-bin your arguments to it
Later, learn how to use the gdb debugger on it.
See also this and that answers.
Using g++, gcc and gfortran on GNU/Linux, I've written a simple script to compile and link together a number of source code files written in C++, C and Fortran. Here are the complete contents of the script. This script has been tested, and works well.
g++ -c test-Q.cpp -I./boost/boost_1_52_0/ -g
gcc -c paul2.c -g
gcc -c paul2_L1.c -g
gcc -c paul6.c -g
gcc -c paul6_L1.c -g
gcc -c fit_slope.c -g
gfortran -c getqpf.F -g
g++ -o test-Q test-Q.o paul2.o paul2_L1.o paul6.o paul6_L1.o fit_slope.o getqpf.o -g -lgfortran
To make this more cross-platform, I would like to re-write the script using Cmake. How might I handle mixed-language compilation?
The following test script listed below does not work, and will only selectively compile some of the files.
Is there perhaps another cross-platform build process that might be better suited for this type of compilation?
cmake_minimum_required (VERSION 2.6)
project (q-test)
include_directories(/media/RESEARCH/SAS2-version2/test-Q/boost/boost_1_52_0)
add_executable( q-test
test-Q.cpp
paul2.c
paul2_L1.c
paul6.c
paul6_L1.c
fit_slope.c
getqpf.F
) # end
You need to enable Fortran for the project like this:
project (q-test C CXX Fortran)
Also, you might want to use find_package(Boost) instead of hard coding an include path.
Here's a simple OCaml program: helloworld.ml
print_string "Hello world...\n" ;;
I'm using OCaml 3.11.0 (MSVC built), VS 2008, and of course FlexDLL
Here's how I compile it (ran from the VS 2008 shell):
ocamlopt helloworld.ml -o helloworld
No executable created. Is there something wrong?
The program compiled and ran on Linux, though.
Show the full output from ocamlopt.
-o helloworld will produce binary helloworld (without extension).
If you want an .exe extension -- specify it explicitly
ocamlopt helloworld.ml -o helloworld.exe