Compiling 64-bit programs

I'm using Visual C++ Express Edition. But I'm working on a cross-platform project, so I'll need to try my code on Linux, MacOS and Solaris too. I was going to move to developing on Linux when the project is ready, but I discovered my VC++ version, which is free and thus very limited, doesn't support 64bit. So I'll need to try things on Linux. I read examples but I'm still not sure what works where: gcc -O3 -mpcu=v9 , something with m64, etc. So I'd like to know the answer to the following simple question: if I have a file called main.cpp and I want to compile it as a 64bit program, what do I type in the command line?
If you're writing for all these platforms, you may want to consider using gcc under cygwin on Windows. That way you'll likely be using the same compiler and you'll have an easier time.
Indeed, but I'm still not sure how to compile a 64-bit program. Is gcc -O3 -mpcu=v9 correct?
If you're on a 64-bit computer, just compile normally.

g++ -o myprogramexecutable myprogram.cpp

If you need to link with some libraries, use -l ("EL", not "EYE")

g++ -o myprogramexecutable myprogram.cpp -lALibrary

If you need to specify where to find the includes, use -I. For libraries, use -L

g++ -o myprogramexecutable myprogram.cpp -lALibrary -I/path/to/my/includes -L/path/to/my/libraries

If you need to compile together many source files, just list them

g++ -o myprogramexecutable myprogramfile1.cpp myprogramfile2.cpp myprogramfile3.cpp -lALibrary -I/path/to/my/includes -L/path/to/my/libraries

Any errors you get are probably just Windows-isms that you need to get rid of.
What is the difference between gcc and g++ in the command line?
Last edited on
IIRC g++ is almost exactly the same as gcc but automatically links the C++ runtime library rather than the C library.

If you want to; you can use GCC to do the same thing; just add -lstdc++ (it might have caps, i.e. -lStdc++ or -lStdC++).
Topic archived. No new replies allowed.