Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why Sublime Text is making the linker ld.exe not link? #1632

Closed
1 of 3 tasks
evandrocoan opened this issue Mar 25, 2017 · 2 comments
Closed
1 of 3 tasks

Why Sublime Text is making the linker ld.exe not link? #1632

evandrocoan opened this issue Mar 25, 2017 · 2 comments
Labels

Comments

@evandrocoan
Copy link

evandrocoan commented Mar 25, 2017

Expected behavior

This error only happens if I call it from a shell script called by Sublime Text .sublime-build file. If I directly call the command g++ --std=c++11 main.cpp -I. -I./yaml-cpp/include -L./yaml-cpp -lyaml-cpp -o main on a command line as mintty 2.6.2 (x86_64-pc-cygwin), it works correctly.

It is expected to the linker to be able to link from Sublime Text.

Actual behavior

undefined reference to `YAML::Parser::~Parser()

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

Steps to reproduce

  1. Clone the project https://github.com/jbeder/yaml-cpp

  2. Open a command line as mintty.exe shell on yaml-cpp folder and build it on windows@cygwin with:

$ 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
  1. Create these following files on the folder yaml-cpp you just cloned:

This is the Sublime Text project.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",

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

And this is the make_run.sh file:

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

Create this file named main.cpp:

#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);
}
  1. Press Ctrl+Shift+B and select the Build Main file option. You will get:

undefined reference to `YAML::Parser::~Parser()

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

But that error only happens if you call make_run.sh from Sublime Text build file. If you open a shell command line as mintty 2.6.2 (x86_64-pc-cygwin) it works correctly calling ./make_run.sh to build.

Why Sublime Text is making the linker ld.exe not link?

Environment

  • Operating system and version:
    • Windows 10 @ mintty 2.6.2 (x86_64-pc-cygwin)
    • Mac OS ...
    • Linux ...
  • Sublime Text:
    • Build 3114

I am on windows with 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.

$ ld --version
GNU ld (GNU Binutils) 2.25.2
Copyright (C) 2014 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

Other issues:

  1. ld: symbol(s) not found for architecture x86_64 jbeder/yaml-cpp#456
  2. undefined reference to `YAML::Parser::~Parser() jbeder/yaml-cpp#481
  3. How to build yaml-cpp on Windows/Cygwin on Sublime Text?
@keith-hall
Copy link
Collaborator

if you execute sh make_run.sh main from a Windows Command Prompt when in the project direcdory, what happens? and does sh launch this mintty 2.6.2 (x86_64-pc-cygwin) shell of yours?

@evandrocoan
Copy link
Author

evandrocoan commented Mar 26, 2017

This happens: (it does compile successfully, which is the opposite of running it from Sublime Text build)

2

It does not launch a windows because I am not launching the mintty shell terminal anywhere on that script. It cannot magically open, but if you put this on the shell script called open_shell.sh and inside it call sh make_run.sh main, it does launch the mintty shell terminal if I call open_shell.sh instead of make_run.sh on the Sublime Text build:

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

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

http://stackoverflow.com/questions/43021055/how-to-build-yaml-cpp-on-windows-cygwin-on-sublime-text/43023460#43023460

This seems to be just more one new issue with the Sublime Text build system:

  1. The build panel, it is severally cutting out lines of its output #1606 _ The build panel, it is severally cutting out lines of its output

The only thing to do overcome these problems is launching a new window running a full shell terminal, as showed on the StackOverflow answer above, instead of relying on the Sublime Text build system/environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants