Question

I'm trying to build opencv source using sublime text 2 but it seems that there is problem in linking opencv libraries using pkg-config

My C++.sublime-build

{
    "cmd": ["g++", "${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++ -ggdb '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}' `pkg-config --cflags --libs opencv`"]
        }
    ]
}

PS: When I try to compile my program from terminal with this compilation is successful.

g++ -ggdb source.cpp `pkg-config --cflags --libs opencv`
Was it helpful?

Solution

I might be too late, but I suppose you should swap pkg-config --cflags --libs opencv and && '${file_path}/${file_base_name}''s position, since pkg-config part is used in compilation, and the && '${file_path}/${file_base_name}' part seems to be the execution part.

"cmd": ["bash", "-c", "g++ -ggdb '${file}' -o '${file_path}/${file_base_name}' pkg-config --cflags --libs opencv && '${file_path}/${file_base_name}' "]

If you're interested, I've created my own build system of it here: http://subokita.com/2013/04/21/configuring-sublime-to-work-with-opencv-on-mac/

OTHER TIPS

For me, actually the command from sub_o did not help, but his input made me understand the way this works, much better. So I want to share my build-system. I have installed everything (opencv, pkg-config, ...) via Homebrew.

{
    "cmd": ["bash", "-c", "g++ '$file' -o '$file_base_name' '-I/usr/local/include' `pkg-config --cflags --libs opencv`"],
    "selector": "source.c++",

    "windows":
    {
        "cmd": ["cl", "/Fo${file_path}", "/O2", "$file"]
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top