1

I'm trying to compile C++ with G++ in 64 bit.

I'm using sublime text 3. This is my build system file :

{
  "cmd": ["g++ ", "-m64", "-std=c++0x", "$file", "-o", "${file_path}/${file_base_name}"],
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
  "working_dir": "${file_path}",
  "selector": "source.c, source.c++, source.cxx, source.cpp",
  "variants": 
  [ 
    {
      "name": "Run",
      "cmd": ["bash", "-c", "g++ -m64 -std=c++0x '${file}' -o '${file_path}/${file_base_name}.exe' &&  xterm -e bash -c '\"${file_path}/${file_base_name}.exe\" ; read'"]  
    }
  ]    
}

Compiled files are still created as 32 bit. When I run g++ --print-multi-lib I get:

32;@m32
   x32;@mx32

I'm sure this has something to do with it, but I'm not sure how to fix it, (Pretty new to this), I've tried installing multilib 64 but nothing has changed.

Any help appreciated. Thank you :)

  • Which operating system? What compiler and version? Also, try to build on the command line, outside of your editor. At first type compilation commands in your terminal. Be sure to compile with `g++ -Wall -g -std=c++11`. Perhaps upgrade your [GCC](http://gcc.gnu.org/) to at least GCC 6. So first learn to compile in your terminal, and later configure your IDE to compile the way you want it to. – Basile Starynkevitch Nov 19 '17 at 17:52
  • 1
    On Linux and Unix, the right commands to understand if an executable is 32 or 64 bits are `file` and `ldd`; the `g++ --print-multi-lib` gives info about compiler configuration – Basile Starynkevitch Nov 19 '17 at 17:55

1 Answers1

2

Your sublime text 3 IDE is confusing and spoiling you and you misconfigured it.

I hope that you are using some POSIX operating system, e.g. Linux.

Learn first to compile on the command line (in some terminal, outside of your editor or IDE). You absolutely need to understand how to invoke the GCC compiler (with commands in a terminal). Here are a few hints.

Be sure to have a recent GCC compiler, at least GCC 6 if you want C++11 or better. Perhaps you need to upgrade your compiler.

compiling a simple single-source program

To compile a single-source C++ program in single.cc into tinyprog executable, use

g++ -std=c++11 -Wall -g single.cc -o tinyprog

FYI, -std=c++11 sets your C++ standard, -Wall ask for almost all warnings (and you might even add -Wextra to get more of them), -g is for debug information (in DWARF) and -o tinyprog sets the output executable. Do ls -l tinyprog, ldd tinyprog, file tinyprog to understand more about your executable.

compiling a simple multi-source program

To compile a small multi-source C++ program, e.g. made of first.cc and second.cc into a smallprog executable

  1. compile each of these into object files

    g++ -std=c++11 -Wall -g -c first.cc -o first.o
    g++ -std=c++11 -Wall -g -c second.cc -o second.o
    
  2. link these object files into your executable

    g++ -std=c++11 -Wall -g first.o second.o -o smallprog
    

building more complex programs

If you are using extra libraries, you may need to add some extra -I includedir option at compile time, and some extra -L libdir and -l libname options at link time. You might want to use pkg-config to help you. You could, if curious, add -v after g++ to be shown the actual steps done by g++

I run g++ --print-multi-lib

This just queries how your g++ compiler has been configured. You could also try g++ -v alone.

Once you are able to compile by (one or several) commands, consider using some build automation tool. To build a single program using GNU make, you could take inspiration from this.

Once you are fluent with compiling thru commands (either directly or thru some build automation tool like make or ninja or thru your script), read the documentation of your editor or IDE to configure it suitably.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547