Sublime Forum

Get SublimeText 3 to comile C++11

#1

Hey guys,

I’m trying to set up a build system to compile C++11 Code. I’m also using libpqxx for some Postgres database stuff. Here’s what I have so far, without the C++11 flags:

[code]{
“cmd”: “g++”, “${file}”, “-o”, “${file_path}/${file_base_name}”, “-I/usr/include/pqxx”, “-lpqxx”, “-lpq”],
“file_regex”: “^(…^:]):([0-9]+):?([0-9]+)?:? (.)$”,
“working_dir”: “${file_path}”,
“selector”: “source.c, source.c++”,

"variants":

	{
		"name": "Run",
		"cmd": "bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' -I'/usr/include/pqxx' -lpqxx -lpq && '${file_path}/${file_base_name}'"]
	}
]

}[/code]

This works fine.

Now I’m trying to get C++11 to work, because I want to use . My GCC/G++ version is 4.9. To get C++11 to work, I used an example build system file I found online, which builds (and build-runs) fine with a testfile, the example is this:

[code]{
“cmd”: “g++”, “-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++”,
“variants”:

{
“name”: “Run”,
“cmd”:“bash”, “-c”, “g++ -std=c++0x ‘${file}’ -o ‘${file_path}/${file_base_name}’ && ‘${file_path}/${file_base_name}’”]
}
]
}[/code]

This also works fine with my testfile, which looks like this:

[code]#include
#include

int main()
{
std::cout << “Works.” << std::endl;
return 0;
}[/code]

Now I want to put things together, so I ended up with this file:

[code]{
“cmd”: “g++”, “-std=c++0x”, “${file}”, “-o”, “${file_path}/${file_base_name}”, “-I/usr/include/pqxx”, “-lpqxx”, “-lpq”],
“file_regex”: “^(…^:]):([0-9]+):?([0-9]+)?:? (.)$”,
“working_dir”: “${file_path}”,
“selector”: “source.c, source.c++”,

"variants":

	{
		"name": "Run",
		"cmd": "bash", "-c", "g++ -std=c++0x '${file}' -o '${file_path}/${file_base_name}' -I'/usr/include/pqxx' -lpqxx -lpq && '${file_path}/${file_base_name}'"]
	}
]

}[/code]

This file doesn’t work at all, I also tried altering the -std=c++0x to -std=c++11 or -std=gnu++11 but I had no luck.
Here is what the compiler gives me with this: http://pastebin.com/v96DkZ4h

What am I doing wrong?

0 Likes

#2

including libraries into sublimes build-in build systems is rather a bad idea, as you would need to change it when you start working on the next project. i would suggest you start using makefiles (as you already got mingw installed) and use the make build system from sublime. works like a charm

edit: if you really want to use sublime as build manager you better put the build system definion in the sublime-project file

0 Likes

#3

So, you turn on C++11, and the header pqxx doesn’t compile. That doesn’t sound a Sublime problem; it’s more likely a libpqxx problem, and you’ll have to ask the libpqxx folks what you need to do to compile their header with C++11. Start by getting the code to compile from the command line, then work on the Sublime build system.

0 Likes