Question

I have a build system configured to build the project with boost (v1.53, Mac OS X Mountain Lion)

{
    "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}", "-I/usr/local/include -L/usr/local/lib -lboost_system"],
    "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}' && '${file_path}/${file_base_name}'"]
        }
    ]
}

However, when I try to test it with a simple program:

#include <iostream>
#include <boost/asio.hpp>

int main(){
    std::cout << "Hello world! - boost" << std::endl;
    return 0;
};

I get the following error (from sublime text 2 output):

Undefined symbols for architecture x86_64:
  "boost::system::system_category()", referenced from:
      __static_initialization_and_destruction_0(int, int)in cct7f9yj.o
      boost::asio::error::get_system_category()    in cct7f9yj.o
  "boost::system::generic_category()", referenced from:
      __static_initialization_and_destruction_0(int, int)in cct7f9yj.o
ld: symbol(s) not found for architecture x86_64
collect2: [Finished in 1.1s with exit code 1]ld returned 1 exit status

With the console output being:

Running g++ /Users/xxxx/Desktop/event_system/main.cpp -o /Users/xxxx/Desktop/event_system/main -I/usr/local/include -L/usr/local/lib -lboost_system

When I copy and paste that same command into terminal, it works without a problem. Is this just an issue with Sublime Text 2 not being able to use g++ correctly? Or is there some other issue.

Was it helpful?

Solution

In Sublime Text 2 build system, each argument for the command should be an individual item in array cmd. If you specify three arguments in one item, they will be passed as only one argument. Take the following setting for example, the python script will only receive one argument whose value is "arg1 arg2 arg3".

{
    "cmd"       : ["python", "${file_path}/${file_base_name}.py", "arg1 arg2 arg3"],
    "selector"  : "source.py",
    "working_dir": "${file_path}"
}

So, in your build system, "-I/usr/local/include -L/usr/local/lib -lboost_system" will be treated as one argument, that is to say, g++ doesn't know that you have specified two link options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top