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

时间:2017-03-25 19:35:49

标签: c++ yaml sublimetext3 sublimetext yaml-cpp

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

我在Cygwin的窗户上:

$ 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

- &GT;

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没有链接?

1 个答案:

答案 0 :(得分:1)

我发现不是在有缺陷的Sublime Text环境中运行东西,而是调用/打开一个shell窗口来运行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"

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