This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?

(35个答案)


去年关闭。




我在安装Stanford C++库时遇到了麻烦,特别是我需要用于项目的Graph相关库。我使用的是Visual Studio IDE和Eclipse IDE,因此特别适合其中一种说明。

我已经做了以下工作:

->在https://stanford.edu/~stepp/cppdoc/下载并解压缩该库

->选择StanfordCPPLib中的'collections'文件夹作为Eclipse / Visual Studio的#include目录

->直到现在,一切似乎仍然有效,并且#include有效。但是在编译期间,会出现大量其他“未解决的内含物”。

请真正安装了磁带库的人/愿意这样做的人可以帮助我做同样的事情。我花了很多时间自己解决这个问题,这是一个主要的瓶颈。

规格:Windows 10 Home
我的密码:
     #include "pch.h"
     #include <iostream>
     #include <collections/basicgraph.h>

     using namespace std;
     int main() {
     BasicGraph g;
     g.addVertex("1");
     g.addVertex("2");
     g.addEdge("1", "2");
    cout<< g.getVertex("1")->name <<endl;
    //boost::optional<int>;
    return 0;
 }

结果:
1>------ Build started: Project: IsolationBranchingImplementation, Configuration: Debug Win32 ------
1>main.cpp
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl stanfordcpplib::staticInitializeLibrary(void)" (?staticInitializeLibrary@stanfordcpplib@@YAXXZ) referenced in function "public: __thiscall stanfordcpplib::StanfordCppLibraryInitializer::StanfordCppLibraryInitializer(void)" (??0StanfordCppLibraryInitializer@stanfordcpplib@@QAE@XZ)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?error@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: void __thiscall Vector<struct Map<class EdgeGen<void *,void *> *,bool>::iterator::NodeMarker>::checkIndex(int,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)const " (?checkIndex@?$Vector@UNodeMarker@iterator@?$Map@PAV?$EdgeGen@PAXPAX@@_N@@@@ABEXHHHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>main.obj : error LNK2019: unresolved external symbol "double __cdecl stringToReal(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?stringToReal@@YANABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: virtual void __thiscall BasicGraphGen<void *,void *>::scanArcData(class TokenScanner &,class EdgeGen<void *,void *> *,class EdgeGen<void *,void *> *)" (?scanArcData@?$BasicGraphGen@PAXPAX@@UAEXAAVTokenScanner@@PAV?$EdgeGen@PAXPAX@@1@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall TokenScanner::getStringValue(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?getStringValue@TokenScanner@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z) referenced in function "private: class VertexGen<void *,void *> * __thiscall Graph<class VertexGen<void *,void *>,class EdgeGen<void *,void *> >::scanNode(class TokenScanner &)" (?scanNode@?$Graph@V?$VertexGen@PAXPAX@@V?$EdgeGen@PAXPAX@@@@AAEPAV?$VertexGen@PAXPAX@@AAVTokenScanner@@@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: enum TokenScanner::TokenType __thiscall TokenScanner::getTokenType(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?getTokenType@TokenScanner@@QBE?AW4TokenType@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: class VertexGen<void *,void *> * __thiscall Graph<class VertexGen<void *,void *>,class EdgeGen<void *,void *> >::scanNode(class TokenScanner &)" (?scanNode@?$Graph@V?$VertexGen@PAXPAX@@V?$EdgeGen@PAXPAX@@@@AAEPAV?$VertexGen@PAXPAX@@AAVTokenScanner@@@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall TokenScanner::nextToken(void)" (?nextToken@TokenScanner@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "public: virtual void __thiscall BasicGraphGen<void *,void *>::scanArcData(class TokenScanner &,class EdgeGen<void *,void *> *,class EdgeGen<void *,void *> *)" (?scanArcData@?$BasicGraphGen@PAXPAX@@UAEXAAVTokenScanner@@PAV?$EdgeGen@PAXPAX@@1@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall TokenScanner::saveToken(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?saveToken@TokenScanner@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: virtual void __thiscall BasicGraphGen<void *,void *>::scanArcData(class TokenScanner &,class EdgeGen<void *,void *> *,class EdgeGen<void *,void *> *)" (?scanArcData@?$BasicGraphGen@PAXPAX@@UAEXAAVTokenScanner@@PAV?$EdgeGen@PAXPAX@@1@Z)
1>C:\Users\Aditya Tyagi\source\repos\IsolationBranchingImplementation\Debug\IsolationBranchingImplementation.exe : fatal error LNK1120: 7 unresolved externals
1>Done building project "IsolationBranchingImplementation.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

最佳答案

基于该错误,它似乎缺少生成可执行文件所需链接的库/实现。您提供的链接中的库作为原始源分发。您需要做的就是将整个库合并到您的项目中,以便您可以将其与自己的代码一起包含和构建。或者,您可以将其构建为一个单独的项目来创建一个静态库,然后可以像当前所做的那样包含其 header ,然后将程序与其生成的库链接起来。

像这样:

MyProject\
  main.cpp
  stanfordlib\
    collections\
      graph.h
      graph.cpp
    ....

然后在您的代码中包括这样的库,
#include "stanfordlib/collections/graph.h"

这将允许您的项目编译lib并将其与您的代码链接。

关于c++ - 无法安装Stanford C++库(图形,BasicGraph类),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55176799/

10-13 09:37