简体   繁体   English

为什么我收到此错误消息:“未定义引用`PerformChat(char *,char *,char *,char *,char *)'”

[英]Why do I get this error message: “undefined reference to `PerformChat(char*, char*, char*, char*, char*)'”

I am trying to compile my program that uses ChatScript libraries. 我正在尝试编译使用ChatScript库的程序。 This is my code inside a file named main.cpp : 这是我在名为main.cpp的文件中的代码:

#include <iostream>

#include "common.h"

using namespace std;


char* output2;
unsigned int InitSystem(int argc,char* argv[]);
void InitStandalone();

int main(int argc, char * argv[])
{
char * userID;
userID="one";


PerformChat("one",NULL,"hi",NULL,output2);

cout<<output2;

    return 0;
}

I tried to include all the ChatScript libraries, also I know the performChat function is within mainSystem.h file that I have included it too(as you can see its in the line 218: https://github.com/bwilcox-1234/ChatScript/blob/master/SRC/mainSystem.h ). 我试图包含所有的ChatScript库,我也知道performChat函数在mainSystem.h文件中,我也包含它(你可以在第218行看到它: https//github.com/bwilcox-1234/ ChatScript / blob / master / SRC / mainSystem.h )。

But after trying to compile my program by this command : 但在尝试使用此命令编译我的程序之后:

g++ -std=c++11 main.cpp constructCode.cpp csocket.cpp dictionarySystem.cpp english.cpp evserver.cpp factSystem.cpp functionExecute.cpp infer.cpp jsmn.cpp json.cpp markSystem.cpp mongodb.cpp mysql.cpp os.cpp outputSystem.cpp patternSystem.cpp postgres.cpp privatesrc.cpp scriptCompile.cpp spellcheck.cpp systemVariables.cpp tagger.cpp testing.cpp textUtilities.cpp tokenSystem.cpp topicSystem.cpp userCache.cpp userSystem.cpp variableSystem.cpp -o myprogram

I got many of this errors!! 我收到了很多这样的错误!!

                                             ^
/tmp/ccuVtYkV.o: In function `main':
main.cpp:(.text+0x36): undefined reference to `PerformChat(char*, char*, char*, char*, char*)'
/tmp/cc6Mhc8u.o: In function `TestIf(char*, FunctionResult&, char*)':
constructCode.cpp:(.text+0x5b): undefined reference to `trace'
constructCode.cpp:(.text+0x203): undefined reference to `trace'
constructCode.cpp:(.text+0x820): undefined reference to `trace'
constructCode.cpp:(.text+0x9d5): undefined reference to `trace'
constructCode.cpp:(.text+0xb62): undefined reference to `trace'
/tmp/cc6Mhc8u.o:constructCode.cpp:(.text+0xbab): more undefined references to `trace' follow
/tmp/cc6Mhc8u.o: In function `HandleIf(char*, char*, FunctionResult&)':
constructCode.cpp:(.text+0xd15): undefined reference to `always'
constructCode.cpp:(.text+0xe75): undefined reference to `trace'
constructCode.cpp:(.text+0x1086): undefined reference to `trace'
constructCode.cpp:(.text+0x11c4): undefined reference to `trace'
/tmp/cc6Mhc8u.o: In function `HandleLoop(char*, char*, FunctionResult&)':
constructCode.cpp:(.text+0x13ab): undefined reference to `trace'
constructCode.cpp:(.text+0x14a7): undefined reference to `trace'
/tmp/cc6Mhc8u.o:constructCode.cpp:(.text+0x298c): more undefined references to `trace' follow
/tmp/ccWaC4y6.o: In function `fillAddr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short, sockaddr_in&)':
csocket.cpp:(.text+0x2320): undefined reference to `hostname'
/tmp/ccWaC4y6.o: In function `Client':
csocket.cpp:(.text+0x37bf): undefined reference to `always'
csocket.cpp:(.text+0x3840): undefined reference to `port'
csocket.cpp:(.text+0x389d): undefined reference to `port'
csocket.cpp:(.text+0x3af1): undefined reference to `port'
csocket.cpp:(.text+0x3b4e): undefined reference to `port'
/tmp/ccWaC4y6.o: In function `RegressLoad(void*)':
csocket.cpp:(.text+0x3f96): undefined reference to `revertBuffer'
csocket.cpp:(.text+0x3fcb): undefined reference to `revertBuffer'
csocket.cpp:(.text+0x401c): undefined reference to `revertBuffer'
csocket.cpp:(.text+0x40b9): undefined reference to `port'
/tmp/ccWaC4y6.o: In function `LogChat(long, char*, char*, char*, int, char*, char*)':
csocket.cpp:(.text+0x4559): undefined reference to `version'
/tmp/ccWaC4y6.o: In function `LaunchClient(void*)':
csocket.cpp:(.text+0x4821): undefined reference to `pthread_create'
/tmp/ccWaC4y6.o: In function `InternetServer()':
csocket.cpp:(.text+0x4a01): undefined reference to `pthread_create'
csocket.cpp:(.text+0x4a1f): undefined reference to `pthread_create'
csocket.cpp:(.text+0x4a38): undefined reference to `pthread_join'
/tmp/ccWaC4y6.o: In function `ServerTransferDataToClient()':
csocket.cpp:(.text+0x4a8d): undefined reference to `ourMainOutputBuffer'
/tmp/ccWaC4y6.o: In function `HandleTCPClient(void*)':
csocket.cpp:(.text+0x5454): undefined reference to `outputLength'
/tmp/ccWaC4y6.o: In function `GrabPort()':
csocket.cpp:(.text+0x5777): undefined reference to `interfaceKind[abi:cxx11]'
csocket.cpp:(.text+0x5799): undefined reference to `port'
csocket.cpp:(.text+0x57c7): undefined reference to `port'
csocket.cpp:(.text+0x57d6): undefined reference to `interfaceKind[abi:cxx11]'
/tmp/ccWaC4y6.o: In function `MainChatbotServer()':
csocket.cpp:(.text+0x5940): undefined reference to `quitting'
csocket.cpp:(.text+0x5a7d): undefined reference to `ourMainInputBuffer'
csocket.cpp:(.text+0x5a83): undefined reference to `ourMainInputBuffer'
csocket.cpp:(.text+0x5a8e): undefined reference to `ourMainInputBuffer'
csocket.cpp:(.text+0x5aa1): undefined reference to `ourMainInputBuffer'
csocket.cpp:(.text+0x5afa): undefined reference to `ourMainInputBuffer'
csocket.cpp:(.text+0x5b1b): undefined reference to `ourMainOutputBuffer'
csocket.cpp:(.text+0x5b3b): undefined reference to `ourMainInputBuffer'
csocket.cpp:(.text+0x5b43): undefined reference to `PerformChat(char*, char*, char*, char*, char*)'
csocket.cpp:(.text+0x5b5b): undefined reference to `Restart()'
csocket.cpp:(.text+0x5bb0): undefined reference to `ourMainInputBuffer'
csocket.cpp:(.text+0x5bd6): undefined reference to `ourMainOutputBuffer'
/tmp/ccwtMWsK.o: In function `ClearWhereInSentence()':
dictionarySystem.cpp:(.text+0x35d): undefined reference to `documentMode'
/tmp/ccwtMWsK.o: In function `AllocateWhereInSentence(WORDENTRY*)':
dictionarySystem.cpp:(.text+0x5ce): undefined reference to `documentMode'
/tmp/ccwtMWsK.o: In function `UseDictionaryFile(char*)':
dictionarySystem.cpp:(.text+0xefc): undefined reference to `language'
dictionarySystem.cpp:(.text+0xf1f): undefined reference to `language'
dictionarySystem.cpp:(.text+0xf3a): undefined reference to `language'
/tmp/ccwtMWsK.o: In function `ReadForeignPosTags(char*)':
dictionarySystem.cpp:(.text+0x10a0): undefined reference to `readBuffer'
dictionarySystem.cpp:(.text+0x10d9): undefined reference to `readBuffer'
/tmp/ccwtMWsK.o: In function `BuildDictionary(char*)':
dictionarySystem.cpp:(.text+0x1402): undefined reference to `language'
dictionarySystem.cpp:(.text+0x157f): undefined reference to `language'
dictionarySystem.cpp:(.text+0x165c): undefined reference to `users'
dictionarySystem.cpp:(.text+0x16ba): undefined reference to `CreateSystem()'
/tmp/ccwtMWsK.o: In function `StoreWord(char*, unsigned long long)':
dictionarySystem.cpp:(.text+0x2915): undefined reference to `server'
/tmp/ccwtMWsK.o: In function `ShowStats(bool)':
dictionarySystem.cpp:(.text+0x31bb): undefined reference to `volleyStartTime'
dictionarySystem.cpp:(.text+0x31c8): undefined reference to `inputSentenceCount'
dictionarySystem.cpp:(.text+0x31d2): undefined reference to `inputSentenceCount'
dictionarySystem.cpp:(.text+0x322b): undefined reference to `tokenCount'
dictionarySystem.cpp:(.text+0x3266): undefined reference to `tokenCount'
dictionarySystem.cpp:(.text+0x326c): undefined reference to `inputSentenceCount'

With g++ -0 test test.cpp , you tell the compiler to compile and link the program, but you miss to tell the compiler where to find the necessary libraries for linking. 使用g++ -0 test test.cpp ,您可以告诉编译器编译和链接程序,但是您错过了告诉编译器在哪里可以找到用于链接的必要库。

If you write g++ -o test.o -c test.cpp , then the compiler will just compile, not link, and you should get a valid test.o object file. 如果你编写g++ -o test.o -c test.cpp ,那么编译器只会编译而不是链接,你应该得到一个有效的test.o目标文件。

Then, you can link everything together. 然后,您可以将所有内容链接在一起 For that, load down a binary from your GIT repository; 为此,从GIT存储库中加载二进制文件; I suppose it's the LinuxChatScript64 file. 我想这是LinuxChatScript64文件。 Place the file, let's say, in the same directory where your .cpp -file resides. 比方说,将文件放在.cpp -file所在的同一目录中。

Then, link with: 然后,链接:

g++ -o myprogram test.o LinuxChatScript64

Hope it works. 希望它有效。 Good luck! 祝好运!

I could compile my program with this command: 我可以用这个命令编译我的程序:

g++ -std=c++11 main.cpp constructCode.cpp duktape/duktape.cpp evserver.cpp csocket.cpp cs_ev.c dictionarySystem.cpp englishTagger.cpp factSystem.cpp json.cpp functionExecute.cpp english.cpp infer.cpp javascript.cpp jsmn.cpp markSystem.cpp mysql.cpp mongodb.cpp os.cpp outputSystem.cpp patternSystem.cpp postgres.cpp privatesrc.cpp scriptCompile.cpp spellcheck.cpp secure.cpp systemVariables.cpp tagger.cpp testing.cpp textUtilities.cpp tokenSystem.cpp topicSystem.cpp userCache.cpp userSystem.cpp variableSystem.cpp mainSystem.cpp -o myapp -L/usr/lib64 -lrt -lcurl -pthread -Ievserver -DDISCARDSERVER=1 -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1 -DEVSERVER=1 -DEVSERVER_FORK=1

I found the options from my makefile and added them at the end of my command as you can see (after -o myapp) 我找到了makefile中的选项,并在我的命令末尾添加了它们,你可以看到(在-o myapp之后)

You can't compile with just the header (.h) files. 您不能只使用标题(.h)文件进行编译。 The header files provide the signatures, but the implementations are in object (.o) files, and need to be linked by the compiler. 头文件提供签名,但实现在对象(.o)文件中,需要由编译器链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM