如何在 Sublime Text 的 Windows/Cygwin 上构建 yaml-cpp?

How to build yaml-cpp on Windows/Cygwin on Sublime Text?

如何在 Windows/Cygwin on Sublime Text 上构建 yaml-cpp?

我正在使用 Cygwin windows:

$ g++ --version
g++ (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

对`YAML::Parser::~Parser()的未定义引用

#include "yaml-cpp/yaml.h"

#include <iostream>
#include <sstream>
#include <cstdlib>

#include <fstream>
#include <string>
#include <vector>

int main( int argumentsCount, char* argumentsStringList[] )
{
    std::ifstream fin("test.beauty-blocks");
    YAML::Parser parser(fin);
}

命令:

g++ --std=c++11 main.cpp -I . -I ./libraries/yaml-cpp/include -L./libraries/yaml-cpp -lyaml-cpp -o main

-->

g++ --std=c++11 main.cpp -I . -I ./libraries/yaml-cpp/include -L./libraries/yaml-cpp -lyaml-cpp -o main
C:\Users\PROFES~1\AppData\Local\Temp\ccRhYWZh.o:main.cpp:(.text+0x1b1): undefined reference to `YAML::Parser::Parser(std::istream&)'
C:\Users\PROFES~1\AppData\Local\Temp\ccRhYWZh.o:main.cpp:(.text+0x2d8): undefined reference to `YAML::Parser::~Parser()'
C:\Users\PROFES~1\AppData\Local\Temp\ccRhYWZh.o:main.cpp:(.text+0x38e): undefined reference to `YAML::Parser::~Parser()'
collect2.exe: error: ld returned 1 exit status

https://github.com/jbeder/yaml-cpp/issues/456相关

我用 yaml-cpp 构建了:

$ cmake -G "Unix Makefiles"
$ make
Scanning dependencies of target yaml-cpp
[  1%] Building CXX object CMakeFiles/yaml-cpp.dir/src/binary.cpp.o
[  3%] Building CXX object CMakeFiles/yaml-cpp.dir/src/convert.cpp.o
[  5%] Building CXX object CMakeFiles/yaml-cpp.dir/src/directives.cpp.o
[  6%] Building CXX object CMakeFiles/yaml-cpp.dir/src/emit.cpp.o
[  8%] Building CXX object CMakeFiles/yaml-cpp.dir/src/emitfromevents.cpp.o
[ 10%] Building CXX object CMakeFiles/yaml-cpp.dir/src/emitter.cpp.o
[ 11%] Building CXX object CMakeFiles/yaml-cpp.dir/src/emitterstate.cpp.o
[ 13%] Building CXX object CMakeFiles/yaml-cpp.dir/src/emitterutils.cpp.o
[ 15%] Building CXX object CMakeFiles/yaml-cpp.dir/src/exceptions.cpp.o
[ 16%] Building CXX object CMakeFiles/yaml-cpp.dir/src/exp.cpp.o
[ 18%] Building CXX object CMakeFiles/yaml-cpp.dir/src/memory.cpp.o
[ 20%] Building CXX object CMakeFiles/yaml-cpp.dir/src/node.cpp.o
[ 21%] Building CXX object CMakeFiles/yaml-cpp.dir/src/node_data.cpp.o
[ 23%] Building CXX object CMakeFiles/yaml-cpp.dir/src/nodebuilder.cpp.o
[ 25%] Building CXX object CMakeFiles/yaml-cpp.dir/src/nodeevents.cpp.o
[ 26%] Building CXX object CMakeFiles/yaml-cpp.dir/src/null.cpp.o
[ 28%] Building CXX object CMakeFiles/yaml-cpp.dir/src/ostream_wrapper.cpp.o
[ 30%] Building CXX object CMakeFiles/yaml-cpp.dir/src/parse.cpp.o
[ 31%] Building CXX object CMakeFiles/yaml-cpp.dir/src/parser.cpp.o
[ 33%] Building CXX object CMakeFiles/yaml-cpp.dir/src/regex_yaml.cpp.o
[ 35%] Building CXX object CMakeFiles/yaml-cpp.dir/src/scanner.cpp.o
[ 36%] Building CXX object CMakeFiles/yaml-cpp.dir/src/scanscalar.cpp.o
[ 38%] Building CXX object CMakeFiles/yaml-cpp.dir/src/scantag.cpp.o
[ 40%] Building CXX object CMakeFiles/yaml-cpp.dir/src/scantoken.cpp.o
[ 41%] Building CXX object CMakeFiles/yaml-cpp.dir/src/simplekey.cpp.o
[ 43%] Building CXX object CMakeFiles/yaml-cpp.dir/src/singledocparser.cpp.o
[ 45%] Building CXX object CMakeFiles/yaml-cpp.dir/src/stream.cpp.o
[ 46%] Building CXX object CMakeFiles/yaml-cpp.dir/src/tag.cpp.o
[ 48%] Building CXX object CMakeFiles/yaml-cpp.dir/src/contrib/graphbuilder.cpp.o
[ 50%] Building CXX object CMakeFiles/yaml-cpp.dir/src/contrib/graphbuilderadapter.cpp.o
[ 51%] Linking CXX static library libyaml-cpp.a
[ 51%] Built target yaml-cpp
Scanning dependencies of target gmock
[ 53%] Building CXX object test/gmock-1.7.0/CMakeFiles/gmock.dir/gtest/src/gtest-all.cc.o
[ 55%] Building CXX object test/gmock-1.7.0/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 56%] Linking CXX static library libgmock.a
[ 56%] Built target gmock
Scanning dependencies of target run-tests
[ 58%] Building CXX object test/CMakeFiles/run-tests.dir/main.cpp.o
[ 60%] Building CXX object test/CMakeFiles/run-tests.dir/ostream_wrapper_test.cpp.o
[ 61%] Building CXX object test/CMakeFiles/run-tests.dir/regex_test.cpp.o
[ 63%] Building CXX object test/CMakeFiles/run-tests.dir/integration/emitter_test.cpp.o
[ 65%] Building CXX object test/CMakeFiles/run-tests.dir/integration/encoding_test.cpp.o
[ 66%] Building CXX object test/CMakeFiles/run-tests.dir/integration/gen_emitter_test.cpp.o
[ 68%] Building CXX object test/CMakeFiles/run-tests.dir/integration/handler_spec_test.cpp.o
[ 70%] Building CXX object test/CMakeFiles/run-tests.dir/integration/handler_test.cpp.o
In file included from D:/source/libraries/yaml-cpp/test/integration/handler_test.cpp:2:0:
D:/source/libraries/yaml-cpp/test/specexamples.h:2:13: warning: ‘{anonymous}::ex2_1’ defined but not used [-Wunused-variable]
 const char *ex2_1 =
             ^
D:/source/libraries/yaml-cpp/test/specexamples.h:7:13: warning: ‘{anonymous}::ex2_2’ defined but not used [-Wunused-variable]
 const char *ex2_2 =
             ^
...
D:/source/libraries/yaml-cpp/test/specexamples.h:839:13: warning: ‘{anonymous}::ex8_22’ defined but not used [-Wunused-variable]
 const char *ex8_22 =
             ^
cc1plus: warning: unrecognized command line option ‘-Wno-c99-extensions’
[ 71%] Building CXX object test/CMakeFiles/run-tests.dir/integration/load_node_test.cpp.o
[ 73%] Building CXX object test/CMakeFiles/run-tests.dir/integration/node_spec_test.cpp.o
[ 75%] Building CXX object test/CMakeFiles/run-tests.dir/node/node_test.cpp.o
[ 76%] Linking CXX executable run-tests.exe
[ 76%] Built target run-tests
Scanning dependencies of target gmock_main
[ 78%] Building CXX object test/gmock-1.7.0/CMakeFiles/gmock_main.dir/gtest/src/gtest-all.cc.o
[ 80%] Building CXX object test/gmock-1.7.0/CMakeFiles/gmock_main.dir/src/gmock-all.cc.o
[ 81%] Building CXX object test/gmock-1.7.0/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 83%] Linking CXX static library libgmock_main.a
[ 83%] Built target gmock_main
Scanning dependencies of target gtest
[ 85%] Building CXX object test/gmock-1.7.0/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 86%] Linking CXX static library libgtest.a
[ 86%] Built target gtest
Scanning dependencies of target gtest_main
[ 88%] Building CXX object test/gmock-1.7.0/gtest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 90%] Linking CXX static library libgtest_main.a
[ 90%] Built target gtest_main
Scanning dependencies of target parse
[ 91%] Building CXX object util/CMakeFiles/parse.dir/parse.cpp.o
[ 93%] Linking CXX executable parse.exe
[ 93%] Built target parse
Scanning dependencies of target sandbox
[ 95%] Building CXX object util/CMakeFiles/sandbox.dir/sandbox.cpp.o
[ 96%] Linking CXX executable sandbox.exe
[ 96%] Built target sandbox
Scanning dependencies of target read
[ 98%] Building CXX object util/CMakeFiles/read.dir/read.cpp.o
[100%] Linking CXX executable read.exe
[100%] Built target read

最初发布于 https://github.com/jbeder/yaml-cpp/issues/481


更新

我刚刚注意到这个错误只有在我从 Sublime Text .sublime-build 文件调用的 shell 脚本中调用它时才会发生。如果我在命令行直接调用命令g++ --std=c++11 main.cpp -I. -I./libraries/yaml-cpp/include -L./libraries/yaml-cpp -lyaml-cpp -o main,就可以了。

这些是 Sublime Text .sublime-project:

{
    "folders":
    [
        {
            "path": ".",
        },
    ],
    "build_systems":
    [
        {
            "file_regex": "^(..[^:]*):([\d+]):?(\d+)?:? (.*)$|^\(.*\)\((\d+)\)(.*)$",
            // "selector": "source.c, source.c++, source.c++11", // comment this to build from everywhere

            "name": "Build Main file",
            "cmd": ["sh", "make_run.sh", "main"],

            "working_dir": "$project_path/source",

            "target": "exec",
            "syntax": "Packages/Text/Plain text.tmLanguage",
        }
    ]
}

这是 make_run.sh 文件:

g++ --std=c++11 main.cpp -I. -I./libraries/yaml-cpp/include -L./libraries/yaml-cpp -lyaml-cpp -o main
exit 0

还在 https://github.com/SublimeTextIssues/Core/issues/1632 上开了一个问题 _ 为什么 Sublime Text 制作 linker ld.exe 而不是 link?

我发现 运行 在有问题的 Sublime Text 环境中,call/open 一个 shell window 到 运行 shell 脚本:

#!/bin/sh


CURRENT_PATH=$(pwd)
COMMAND_TO_RUN="pwd; echo $CURRENT_PATH; cd $CURRENT_PATH; sh make_run.sh $@"

echo "choose_a_compiler.sh: $CURRENT_PATH"


current_terminal="mintty"

if command -v $current_terminal >/dev/null 2>&1; then
    /bin/$current_terminal -w max -h always -e /bin/bash --login -i -c "$COMMAND_TO_RUN"
    exit 0
fi


current_terminal="xfce4-terminal"

if command -v $current_terminal >/dev/null 2>&1; then
    /usr/bin/$current_terminal --maximize --hold --command="$COMMAND_TO_RUN"
    exit 0
fi


# TODO
# "konsole" "gnome-terminal" "xterm"

刚刚用此脚本 choose_a_compiler.sh 替换了 .sublime-build 文件中的 "make_run.sh,并在该脚本中调用了您的 make_run.sh。现在一切都很好,但遗憾的是它是在一个新的 windows 上,而不是在 Sublime Text 构建输出控制台上。