为什么我得到“未定义的引用...”我加入图书馆的错误? [英] Why do I get "undefined reference to ..." errors when I included the library?

查看:158
本文介绍了为什么我得到“未定义的引用...”我加入图书馆的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请查看这个github,它解释了如何将ChatScript用作C / C ++程序中的库(仅参见嵌入步骤1和2): [ ^ ]



正如教程所说,我必须做2次电话。

1. InitSystem()函数调用初始化库。

2-performChat()函数将字符串传递给库并获取输出字符串作为答案。 br $> b $ b

我尝试了什么:



所以我写了这个简单的C ++代码:



 #include< iostream> 
#includecommon.h
#includemainSystem.h

using namespace std;


int main(int argc,char * argv [])
{
char * input =hi;
char *输出;
char * userID =one;

InitSystem(0,NULL);
void InitStandalone();

PerformChat(一个,哈利,输入,NULL,输出);

cout<< output;

返回0;
}





我知道上面提到的两个函数都在mainSystem.cpp中,所以我确实把这个文件包含在我的程序。(这是mainSystem.h: https://github.com/bwilcox-1234 /ChatScript/blob/master/SRC/mainSystem.h 这是mainSystem.cpp https://github.com/bwilcox-1234/ChatScript/blob/master/SRC/mainSystem.cpp



一切看起来不错但是当我尝试通过

 g ++ -o mayprogram main.o 

编译我的代码时,它说:



 main.o:在函数`main'中:
main.cpp :(。text + 0x44):未定义引用`InitSystem(int,char **,char *,char *,char *) ,USERFILESYSTEM *,void(*)(char *),void(*)(char *))'
main.cpp :(。text + 0x6a):未定义引用`PerformChat(char *,char *, char *,char *,char *)'
collect2:错误:ld retu 1退出状态





这对我来说很奇怪!!!当我在我的代码上方包含mainSystem.h时,为什么会出现此错误消息?



***关于main.o我必须说我是通过运行< pre lang =c ++>之前使用

 main.cpp 

成为独立的

命令!



这是make文件:



 .PHONY =干净二进制服务器debugserver独立pgserver debugpgserver mysqlserver debugmysqlserver mongoserver debugmongoserver foreignserver mongotreetaggerserver 

#删除了'all'目标。它没有意义,因为每个构建目标需要一组不同的定义。
#所以我们需要在构建每个目标之前进行清理,以便编译正确的东西。

#例如构建pg和mysql:

#1. make clean pgserver
#2。make clean mysqlserver

#注意:在Ubuntu上构建mysql目标:
#sudo apt-get install libmysqlclient-dev

#在make变量中存储可执行文件名,以便cleanall目标工作
executable.server = .. / BINARIES / ChatScript
server:DEFINES + = -DLOCKUSERFILE = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1
server:PGLOAD = -pthread
server:INCLUDEDIRS = -Ievserver
服务器:二进制
服务器:EXECUTABLE = $(executable.server)
服务器:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno -char-subscripts -Wno-strict-aliasing

executable.debugserver = .. / BINARIES / ChatScriptDebug
debugserver:DEFINES + = -DLOCKUSERFILE = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1 -DDEBUG -DEVSERVER = 1 -DEVSERVER_FORK = 1
debugserver:PGLOAD = -pthread
debugserver:INCLUDEDIRS = -Ievserver
debugserver:b inary
debugserver:EXECUTABLE = $(executable.debugserver)
debugserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.standalone = .. / BINARIES / CS_LINUX
standalone:DEFINES + = -DDISCARDSERVER = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1
standalone:PGLOAD = -pthread
standalone:INCLUDEDIRS = -Ievserver
standalone:binary
standalone:EXECUTABLE = $(executable.standalone)
standalone:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing

executable。 pgserver = .. / BINARIES / ChatScriptpg
pgserver:DEFINES + = -DLOCKUSERFILE = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1
pgserver:PGLOAD = -lpq -pthread
pgserver:binary
pgserver:EXECUTABLE = $(executable.pgserver)
pgserver:INCLUDEDIRS = -Ievserver -Ipostgres
pgserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing

executable.debugpgserver = .. / BINARIES / ChatScriptpgDebug
debugpgserver :DEFINES + = -DLOCKUSERFILE = 1 -DDEBUG -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1
debugpgserver:PGLOAD = -lpq -pthread
debugpgserver:INCLUDEDIRS = -Ievserver -Ipostgres
debugpgserver:binary
debugpgserver:EXECUTABLE = $(executable.debugpgserver)
debugpgserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings - Wno-char-subscripts -Wno-strict-aliasing -g

executable.mysqlserver = .. / BINARIES / ChatScriptMysql
mysqlserver:DEFINES + = -DLOCKUSERFILE = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1
mysqlserver:PGLOAD = -lmysqlclient -pthread
mysqlserver:binary
mysqlserver:EXECUTABLE = $(executable.mysqlserver)
mysqlserver:INCLUDEDIRS = -Ievserver
mysqlserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing

executable.debugmysqlserver = .. / BINARIES / ChatScriptMysqlDebug
debugmysqlserver:DEFINES + = -DLOCKUSERFILE = 1 -DDEBUG -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1
debugmysqlserver:PGLOAD = -lmysqlclient -pthread
debugmysqlserver:INCLUDEDIRS = -Ievserver
debugmysqlserver:binary
debugmysqlserver :EXECUTABLE = $(executable.debugmysqlserver)
debugmysqlserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.mongoserver = .. / BINARIES / ChatScriptMongo
mongoserver:DEFINES + = -DLOCKUSERFILE = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMYSQL = 1
mongoserver:PGLOAD = -pthread
mongoserver:binary
mongoserver:EXECUTABLE = $(executable.mongoserver)
mongoserver:INCLUDEDIRS = -Iinclude -I / usr / local / include / libbson- 1.0 -I / usr / local / include / libmongoc-1.0
mongos erver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.debugmongoserver = .. / BINARIES / ChatScriptMongoDebug
debugmongoserver:DEFINES + = -DLOCKUSERFILE = 1 -DDEBUG -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMYSQL = 1
debugmongoserver:PGLOAD = -lpq -pthread
debugmongoserver:binary
debugmongoserver:INCLUDEDIRS = -Iinclude -I / usr / local / include / libbson-1.0 -I / usr / local / include / libmongoc-1.0
debugmongoserver:EXECUTABLE = $( executable.debugmongoserver)
debugmongoserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.foreignserver = .. / BINARIES / ChatScriptForeign
foreignserver:DEFINES + = -DLOCKUSERFILE = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1 -DTREETAGGER = 1
foreignserver:PGLOAD = -pthread -L ../ treetagger -L ../ BINARIES -ltreetagger
foreignserver:INCLUDEDIRS = -Ievserver
foreignserver:binary
foreignserver:EXECUTABLE = $(executable.foreignserver)
foreignserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned -char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing

executable.mongotreetaggerserver = .. / BINARIES / ChatScriptMongoForeign
mongotreetaggerserver:DEFINES + = -DLOCKUSERFILE = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMYSQL = 1 -DTREETAGGER = 1
mongotreetaggerserver:PGLOAD = -pthread -L ../ treetagger -L ../ BINARIES -ltreetagger
mongotreetaggerserver: INCLUDEDIRS = -Iinclude -I / usr / local / include / libbson-1.0 -I / usr / local / include / libmongoc-1.0
mongotreetaggerserver:binary
mongotreetaggerserver:EXECUTABLE = $(executable.mongotreetaggerserver)
mongotreetaggerserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing

UNAME: = $(shell uname)

CC = g ++

ifeq($(UNA) ME),Linux)
$(info ************ LINUX VERSION ************)
LDFLAGS = -L / usr / lib64 -lrt -lcurl --verbose $(PGLOAD)
mongoserver:LDFLAGS + = -lcrypt -lsasl2 -L / usr / local / lib -lmongoc-1.0 -lbson-1.0
debugmongoserver:LDFLAGS + = -lcrypt -lsasl2 -L / usr / local / lib -lmongoc-1.0 -lbson-1.0
mongotreetaggerserver:LDFLAGS + = -lcrypt -lsasl2 -L / usr / local / lib -lmongoc-1.0 -lbson-1.0
endif

ifeq($(UNAME),Darwin)
OSXRELEASE:= $(shell默认读取loginwindow SystemVersionStampAsString)
$(info ********** ** MAC VERSION $ OSXRELEASE检测到************)
LDFLAGS = -mmacosx-version-min = $(OSXRELEASE)-lcurl $(PGLOAD)
CFLAGS = - mmacosx-version-min = $(OSXRELEASE)-c -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts
endif

ifeq($(UNAME), FreeBSD)
$(info ************ FREEBSD VERSION ************)
DEFINES + = -DFREEBSD = 1
INCLUDEDIRS + = -I / usr / local / include
LDFLAGS = -L / usr / local / lib -lrt -lcurl -lev --v erbose $(PGLOAD)
mongoserver:LDFLAGS + = -lgcrypt -lsasl2 -lmongoc-1.0 -lbson-1.0
debugmongoserver:LDFLAGS + = -lgcrypt -lsasl2 -lmongoc-1.0 -lbson-1.0
mongotreetaggerserver :LDFLAGS + = -lgcrypt -lsasl2 -lmongoc-1.0 -lbson-1.0
endif

SOURCES = 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
OBJECTS = $(SOURCES: .cpp = .o)

默认值:server

clean:
-rm -f * .o

cleanall:clean
-rm -f $(executable.server)
-rm -f $(executable.debugserver)
-rm -f $(ex ecutable.standalone)
-rm -f $(executable.pgserver)
-rm -f $(executable.debugpgserver)
-rm -f $(executable.mysqlserver)
-rm -f $(executable.debugmysqlserver)
-rm -f $(executable.mongoserver)
-rm -f $(executable.debugmongoserver)
-rm -f $(可执行文件。 foreignserver)
-rm -f $(executable.mongotreetaggerserver)

binary:$(OBJECTS)
$(CC)$(OBJECTS)$(LDFLAGS)$(DEFINES) $(INCLUDEDIRS)-o $(EXECUTABLE)

.cpp.o:
$(CC)$(CFLAGS)$(DEFINES)$(INCLUDEDIRS)$< -o $ @







编辑:当我尝试这个命令时:

 g ++ -std = c ++ 11 -o myprogram 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 





它给了我这个结果:



 ^ 
/tmp/ccU6n5Cp.o:在函数`CurlShutdown()'中:
json.cpp :(。text + 0x1863):未定义引用`curl_global_cleanup'
/tmp/ccU6n5Cp.o:函数`InitCurl()':
json.cpp :(。text + 0x1882):未定义引用`curl_global_init'
/tmp/ccU6n5Cp.o:函数`urlEncodePiece(char *)':
json.cpp :(。text + 0x18b5):未定义引用`curl_easy_init'
json.cpp :(。text + 0x1902):未定义引用`curl_easy_escape'
json.cpp :(。text + 0x193a):未定义引用`curl_free'
json.cpp :(。text + 0x1946):未定义引用`curl_easy_cleanup'
/tmp/ccU6n5Cp.o:函数`encodeSegment(char **,char *,char *,void *)':
json.cpp :( .text + 0x1a05):未定义引用`curl_easy_escape'
json.cpp :(。text + 0x1a28):未定义引用`curl_free'
/tmp/ccU6n5Cp.o:函数`JSONOpenCode(char *)':
json.cpp :(。text + 0x236d):未定义引用`curl_easy_init'
json.cpp :(。text + 0x255e):未定义引用`curl_easy_setopt'
json.cpp :(。text + 0x257e):未定义引用`curl_easy_setopt'
json.cpp :(。text + 0x25a5):未定义引用`curl_easy_setopt'
json.cpp :(。text + 0x25c5):未定义引用`curl_easy_setopt'
json.cpp :(。text + 0x25ec):未定义引用`curl_easy_setopt'
/tmp/ccU6n5Cp.o:json.cpp:(.text+0x260c):更多未定义对'curl_easy_setopt'的引用遵循
/tmp/ccU6n5Cp.o:函数`JSONOpenCode(char *)':
json.cpp :(。text + 0x2620):未定义引用`curl_slist_append'
json.cpp :(。text + 0x2991):未定义引用`curl_slist_append'
json.cpp :(。text + 0x2bc2):未定义引用`curl_easy_setopt'
json.cpp :(。 text + 0x2c28):未定义引用`curl_easy_setopt'
json.cpp :(。text + 0x2c8a):未定义引用`curl_easy_setopt'
json.cpp :(。text + 0x2cf7):undefined reference to `curl_easy_setopt'
json.cpp :(。text + 0x2d26):未定义引用`curl_easy_setopt'
/tmp/ccU6n5Cp.o:json.cpp:(.text+0x2d53):更多未定义的引用`curl_easy_setopt'跟随
/tmp/ccU6n5Cp.o:在函数`JSONOpenCode(char *)'中:
json.cpp :(。text + 0x2ea7):undefined referenc e到`curl_easy_perform'
json.cpp :(。text + 0x2ecb):未定义引用`curl_easy_getinfo'
json.cpp :(。text + 0x31cf):未定义引用`curl_slist_free_all'
json.cpp :(。text + 0x31de):未定义引用`curl_easy_cleanup'
/tmp/ccaIe2WK.o:函数`mysqlUserRead(void *,unsigned long,unsigned long,_IO_FILE *)':
mysql.cpp :(。text + 0xe5):未定义引用`mysql_stmt_init'
mysql.cpp :(。text + 0x10c):未定义引用`mysql_error'
mysql.cpp :(。 text + 0x14e):未定义引用`mysql_stmt_prepare'
mysql.cpp :(。text + 0x16b):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x1fe):undefined reference to `mysql_stmt_bind_param'
mysql.cpp :(。text + 0x21b):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x241):未定义引用`mysql_stmt_execute'
mysql .cpp :(。text + 0x25e):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x284):undefined reference t o`mysql_stmt_store_result'
mysql.cpp :(。text + 0x2a1):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x2c7):未定义引用`mysql_stmt_num_rows'
mysql.cpp :(。text + 0x360):未定义引用`mysql_stmt_bind_result'
mysql.cpp :(。text + 0x37d):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x3a3):未定义引用`mysql_stmt_fetch'
mysql.cpp :(。text + 0x3ea):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x420):未定义引用`mysql_stmt_error '
/tmp/ccaIe2WK.o:函数`mysqlUserWrite(void const *,unsigned long,unsigned long,_IO_FILE *)':
mysql.cpp :(。text + 0x56f):undefined reference to `mysql_stmt_init'
mysql.cpp :(。text + 0x596):未定义引用`mysql_error'
mysql.cpp :(。text + 0x5d8):未定义引用`mysql_stmt_prepare'
mysql .cpp :(。text + 0x5f5):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x6cb):undefined ref erence to`mysql_stmt_bind_param'
mysql.cpp :(。text + 0x6e8):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x719):未定义引用`mysql_stmt_execute'
mysql.cpp :(。text + 0x731):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x747):未定义引用`mysql_stmt_errno'
mysql.cpp :(。text + 0x784):未定义引用`mysql_stmt_affected_rows'
mysql.cpp :(。text + 0x7c0):未定义引用`mysql_stmt_init'
mysql.cpp :(。text + 0x7e7):未定义引用` mysql_error'
mysql.cpp :(。text + 0x829):未定义引用`mysql_stmt_prepare'
mysql.cpp :(。text + 0x846):未定义引用`mysql_stmt_error'
mysql。 cpp :(。text + 0x91c):未定义引用`mysql_stmt_bind_param'
mysql.cpp :(。text + 0x939):未定义引用`mysql_stmt_error'
mysql.cpp :(。text + 0x95f) :未定义引用`mysql_stmt_execute'
mysql.cpp :(。text + 0x97c):未定义引用`mysql_stm t_error'
mysql.cpp :(。text + 0x9a2):未定义引用`mysql_stmt_affected_rows'
mysql.cpp :(。text + 0x9c7):未定义引用`mysql_stmt_error'
/ tmp /ccaIe2WK.o:在函数`MySQLUserFilesCode()'中:
mysql.cpp :(。text + 0xa09):未定义引用`mysql_init'
mysql.cpp :(。text + 0xa66):undefined引用`mysql_real_connect'
mysql.cpp :(。text + 0xa91):未定义引用`mysql_error'
/tmp/ccaIe2WK.o:函数`MySQLInitCode(char *)':
mysql.cpp :(。text + 0xb45):未定义引用`mysql_init'
mysql.cpp :(。text + 0xb72):未定义引用`mysql_real_connect'
mysql.cpp :(。text + 0xb8c):未定义引用`mysql_error'
mysql.cpp :(。text + 0xbc3):未定义引用`mysql_query'
mysql.cpp :(。text + 0xbd8):未定义引用` mysql_error'
mysql.cpp :(。text + 0xc0a):未定义引用`mysql_use_result'
mysql.cpp :(。text + 0xc24):未定义引用`mysql_fetch_row'
mysql.cpp :(。text + 0xc5b):未定义引用`mysql_free_result'
mysql.cpp :(。text + 0xc67):未定义引用`mysql_close'
collect2:错误:ld返回1退出状态

解决方案

(executable.server)
服务器:CFLAGS = -c -std = c ++ 11 - Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing

executable.debugserver = .. / BINARIES / ChatScriptDebug
debugserver:DEFINES + = - DLOCKUSERFILE = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1 -DDEBUG -DEVSERVER = 1 -DEVSERVER_FORK = 1
debugserver:PGLOAD = -pthread
debugserver:INCLUDEDIRS = -Ievserver
debugserver :binary
debugserver:EXECUTABLE =


(executable.debugserver)
debugserver:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char - Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.standalone = .. / BINARIES / CS_LINUX
standalone:DEFINES + = -DDISCARDSERVER = 1 -DDISCARDPOSTGRES = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1
standalone:PGLOAD = -pthread
standalone:INCLUDEDIRS = -Ievserver
standalone:binary
standalone:EXECUTABLE =


(executable.standalone)
standalone:CFLAGS = -c -std = c ++ 11 -Wall -funsigned-char -Wno-write -strings -Wno-char-subscripts -Wno-strict-aliasing

executable.pgserver = .. / BINARIES / ChatScriptpg
pgserver:DEFINES + = -DLOCKUSERFILE = 1 -DEVSERVER = 1 -DEVSERVER_FORK = 1 -DDISCARDMONGO = 1 -DDISCARDMYSQL = 1
pgserver:PGLOAD = -lpq -pthread
pgserver:binary
pgserver:EXECUTABLE =


Please look at this github that explains how to use ChatScript as a library inside a C/C++ program(only see Embedding step1 and 2): [^]

As the tutorial says, I must do 2 calls.
1. InitSystem() function call to initialize the library.
2-performChat() function to pass a string to library and get the output string as the answer.

What I have tried:

So I wrote this simple C++ code:

#include <iostream>
#include "common.h"
#include "mainSystem.h"

using namespace std;


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

InitSystem (0, NULL);
void InitStandalone();

PerformChat("one","Harry",input,NULL,output);

cout<<output;

    return 0;
}



And I know both the mentioned functions are inside of mainSystem.cpp, so I did include that file to my program.(this is mainSystem.h : https://github.com/bwilcox-1234/ChatScript/blob/master/SRC/mainSystem.h and this is mainSystem.cpp https://github.com/bwilcox-1234/ChatScript/blob/master/SRC/mainSystem.cpp)

Everything looks OK but when I try to compile my code by

g++ -o mayprogram main.o

it says:

main.o: In function `main':
main.cpp:(.text+0x44): undefined reference to `InitSystem(int, char**, char*, char*, char*, USERFILESYSTEM*, void (*)(char*), void (*)(char*))'
main.cpp:(.text+0x6a): undefined reference to `PerformChat(char*, char*, char*, char*, char*)'
collect2: error: ld returned 1 exit status



It's very strange for me!!! Why do I get this error message when I included the mainSystem.h above my code?

***about main.o I must say I built it by running

make standalone

command before, with my

main.cpp

successfully!

This is the make file:

.PHONY = clean binary server debugserver standalone pgserver debugpgserver mysqlserver debugmysqlserver mongoserver debugmongoserver foreignserver mongotreetaggerserver 

# Removed the 'all' target.  It does not  make sense since each build target requires a different set of defines.
# So we need to clean before building each target in order compile in the right stuff.  
#
# E.g. to build pg and mysql:
#
# 1. make clean pgserver
# 2. make clean mysqlserver

# Note: to build mysql targets on Ubuntu:
# sudo apt-get install libmysqlclient-dev

# store executable names in make variables so that cleanall target works
executable.server=../BINARIES/ChatScript
server: DEFINES+= -DLOCKUSERFILE=1  -DEVSERVER=1 -DEVSERVER_FORK=1  -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1 
server: PGLOAD= -pthread
server: INCLUDEDIRS=-Ievserver
server: binary
server: EXECUTABLE=$(executable.server)
server: CFLAGS=-c  -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 

executable.debugserver=../BINARIES/ChatScriptDebug
debugserver: DEFINES+= -DLOCKUSERFILE=1 -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1  -DDEBUG -DEVSERVER=1 -DEVSERVER_FORK=1 
debugserver: PGLOAD= -pthread
debugserver: INCLUDEDIRS=-Ievserver
debugserver: binary
debugserver: EXECUTABLE=$(executable.debugserver)
debugserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.standalone=../BINARIES/CS_LINUX
standalone: DEFINES+=  -DDISCARDSERVER=1 -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1 -DEVSERVER=1 -DEVSERVER_FORK=1
standalone: PGLOAD= -pthread
standalone: INCLUDEDIRS=-Ievserver
standalone: binary
standalone: EXECUTABLE=$(executable.standalone)
standalone: CFLAGS=-c -std=c++11  -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 

executable.pgserver=../BINARIES/ChatScriptpg
pgserver: DEFINES+= -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1
pgserver: PGLOAD= -lpq -pthread
pgserver: binary
pgserver: EXECUTABLE=$(executable.pgserver)
pgserver: INCLUDEDIRS=-Ievserver -Ipostgres
pgserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 

executable.debugpgserver=../BINARIES/ChatScriptpgDebug
debugpgserver: DEFINES+= -DLOCKUSERFILE=1  -DDEBUG -DEVSERVER=1 -DEVSERVER_FORK=1  -DDISCARDMONGO=1 -DDISCARDMYSQL=1
debugpgserver: PGLOAD= -lpq -pthread
debugpgserver: INCLUDEDIRS=-Ievserver -Ipostgres 
debugpgserver: binary
debugpgserver: EXECUTABLE=$(executable.debugpgserver)
debugpgserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.mysqlserver=../BINARIES/ChatScriptMysql
mysqlserver: DEFINES+= -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1
mysqlserver: PGLOAD= -lmysqlclient -pthread
mysqlserver: binary
mysqlserver: EXECUTABLE=$(executable.mysqlserver)
mysqlserver: INCLUDEDIRS=-Ievserver 
mysqlserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 

executable.debugmysqlserver=../BINARIES/ChatScriptMysqlDebug
debugmysqlserver: DEFINES+= -DLOCKUSERFILE=1  -DDEBUG -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1  
debugmysqlserver: PGLOAD= -lmysqlclient -pthread 
debugmysqlserver: INCLUDEDIRS=-Ievserver
debugmysqlserver: binary
debugmysqlserver: EXECUTABLE=$(executable.debugmysqlserver)
debugmysqlserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.mongoserver=../BINARIES/ChatScriptMongo
mongoserver: DEFINES+= -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDPOSTGRES=1 -DDISCARDMYSQL=1
mongoserver: PGLOAD= -pthread
mongoserver: binary
mongoserver: EXECUTABLE=$(executable.mongoserver)
mongoserver: INCLUDEDIRS=-Iinclude -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0
mongoserver: CFLAGS=-c -std=c++11  -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.debugmongoserver=../BINARIES/ChatScriptMongoDebug
debugmongoserver: DEFINES+= -DLOCKUSERFILE=1  -DDEBUG -DEVSERVER=1 -DEVSERVER_FORK=1  -DDISCARDPOSTGRES=1  -DDISCARDMYSQL=1
debugmongoserver: PGLOAD= -lpq -pthread
debugmongoserver: binary
debugmongoserver: INCLUDEDIRS=-Iinclude -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0
debugmongoserver: EXECUTABLE=$(executable.debugmongoserver)
debugmongoserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g

executable.foreignserver=../BINARIES/ChatScriptForeign
foreignserver: DEFINES+= -DLOCKUSERFILE=1  -DEVSERVER=1 -DEVSERVER_FORK=1  -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1 -DTREETAGGER=1
foreignserver: PGLOAD= -pthread -L../treetagger -L../BINARIES -ltreetagger
foreignserver: INCLUDEDIRS=-Ievserver
foreignserver: binary
foreignserver: EXECUTABLE=$(executable.foreignserver)
foreignserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 

executable.mongotreetaggerserver=../BINARIES/ChatScriptMongoForeign
mongotreetaggerserver: DEFINES+= -DLOCKUSERFILE=1  -DEVSERVER=1 -DEVSERVER_FORK=1  -DDISCARDPOSTGRES=1  -DDISCARDMYSQL=1 -DTREETAGGER=1
mongotreetaggerserver: PGLOAD= -pthread -L../treetagger -L../BINARIES -ltreetagger
mongotreetaggerserver: INCLUDEDIRS=-Iinclude -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0
mongotreetaggerserver: binary
mongotreetaggerserver: EXECUTABLE=$(executable.mongotreetaggerserver)
mongotreetaggerserver: CFLAGS=-c -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing 

UNAME := $(shell uname)

CC=g++

ifeq ($(UNAME), Linux)
$(info ************ LINUX VERSION ************)
LDFLAGS= -L/usr/lib64 -lrt -lcurl  --verbose $(PGLOAD)
mongoserver: LDFLAGS+= -lcrypt -lsasl2 -L/usr/local/lib -lmongoc-1.0 -lbson-1.0 
debugmongoserver: LDFLAGS+= -lcrypt -lsasl2 -L/usr/local/lib -lmongoc-1.0 -lbson-1.0 
mongotreetaggerserver: LDFLAGS+= -lcrypt -lsasl2 -L/usr/local/lib -lmongoc-1.0 -lbson-1.0 
endif

ifeq ($(UNAME), Darwin)
OSXRELEASE := $(shell defaults read loginwindow SystemVersionStampAsString)
$(info ************ MAC VERSION $OSXRELEASE detected ************)
LDFLAGS=-mmacosx-version-min=$(OSXRELEASE) -lcurl $(PGLOAD)  
CFLAGS=-mmacosx-version-min=$(OSXRELEASE) -c  -Wall  -funsigned-char -Wno-write-strings -Wno-char-subscripts 
endif

ifeq ($(UNAME), FreeBSD)
$(info ************ FREEBSD VERSION ************)
DEFINES+= -DFREEBSD=1
INCLUDEDIRS+= -I/usr/local/include
LDFLAGS= -L/usr/local/lib -lrt -lcurl -lev  --verbose $(PGLOAD)
mongoserver: LDFLAGS+= -lgcrypt -lsasl2 -lmongoc-1.0 -lbson-1.0 
debugmongoserver: LDFLAGS+= -lgcrypt -lsasl2 -lmongoc-1.0 -lbson-1.0 
mongotreetaggerserver: LDFLAGS+= -lgcrypt -lsasl2 -lmongoc-1.0 -lbson-1.0 
endif

SOURCES=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 
OBJECTS=$(SOURCES:.cpp=.o)

default: server

clean:
	-rm -f *.o

cleanall: clean
	-rm -f $(executable.server)
	-rm -f $(executable.debugserver)
	-rm -f $(executable.standalone)
	-rm -f $(executable.pgserver)
	-rm -f $(executable.debugpgserver)
	-rm -f $(executable.mysqlserver)
	-rm -f $(executable.debugmysqlserver)
	-rm -f $(executable.mongoserver)
	-rm -f $(executable.debugmongoserver)
	-rm -f $(executable.foreignserver)
	-rm -f $(executable.mongotreetaggerserver)

binary: $(OBJECTS)
	$(CC) $(OBJECTS) $(LDFLAGS) $(DEFINES) $(INCLUDEDIRS) -o $(EXECUTABLE)

.cpp.o:
	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDEDIRS) $< -o $@




EDIT: when I try this command:

g++ -std=c++11 -o myprogram 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 



It gives me this result:

                                                    ^
/tmp/ccU6n5Cp.o: In function `CurlShutdown()':
json.cpp:(.text+0x1863): undefined reference to `curl_global_cleanup'
/tmp/ccU6n5Cp.o: In function `InitCurl()':
json.cpp:(.text+0x1882): undefined reference to `curl_global_init'
/tmp/ccU6n5Cp.o: In function `UrlEncodePiece(char*)':
json.cpp:(.text+0x18b5): undefined reference to `curl_easy_init'
json.cpp:(.text+0x1902): undefined reference to `curl_easy_escape'
json.cpp:(.text+0x193a): undefined reference to `curl_free'
json.cpp:(.text+0x1946): undefined reference to `curl_easy_cleanup'
/tmp/ccU6n5Cp.o: In function `encodeSegment(char**, char*, char*, void*)':
json.cpp:(.text+0x1a05): undefined reference to `curl_easy_escape'
json.cpp:(.text+0x1a28): undefined reference to `curl_free'
/tmp/ccU6n5Cp.o: In function `JSONOpenCode(char*)':
json.cpp:(.text+0x236d): undefined reference to `curl_easy_init'
json.cpp:(.text+0x255e): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x257e): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x25a5): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x25c5): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x25ec): undefined reference to `curl_easy_setopt'
/tmp/ccU6n5Cp.o:json.cpp:(.text+0x260c): more undefined references to `curl_easy_setopt' follow
/tmp/ccU6n5Cp.o: In function `JSONOpenCode(char*)':
json.cpp:(.text+0x2620): undefined reference to `curl_slist_append'
json.cpp:(.text+0x2991): undefined reference to `curl_slist_append'
json.cpp:(.text+0x2bc2): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x2c28): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x2c8a): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x2cf7): undefined reference to `curl_easy_setopt'
json.cpp:(.text+0x2d26): undefined reference to `curl_easy_setopt'
/tmp/ccU6n5Cp.o:json.cpp:(.text+0x2d53): more undefined references to `curl_easy_setopt' follow
/tmp/ccU6n5Cp.o: In function `JSONOpenCode(char*)':
json.cpp:(.text+0x2ea7): undefined reference to `curl_easy_perform'
json.cpp:(.text+0x2ecb): undefined reference to `curl_easy_getinfo'
json.cpp:(.text+0x31cf): undefined reference to `curl_slist_free_all'
json.cpp:(.text+0x31de): undefined reference to `curl_easy_cleanup'
/tmp/ccaIe2WK.o: In function `mysqlUserRead(void*, unsigned long, unsigned long, _IO_FILE*)':
mysql.cpp:(.text+0xe5): undefined reference to `mysql_stmt_init'
mysql.cpp:(.text+0x10c): undefined reference to `mysql_error'
mysql.cpp:(.text+0x14e): undefined reference to `mysql_stmt_prepare'
mysql.cpp:(.text+0x16b): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x1fe): undefined reference to `mysql_stmt_bind_param'
mysql.cpp:(.text+0x21b): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x241): undefined reference to `mysql_stmt_execute'
mysql.cpp:(.text+0x25e): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x284): undefined reference to `mysql_stmt_store_result'
mysql.cpp:(.text+0x2a1): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x2c7): undefined reference to `mysql_stmt_num_rows'
mysql.cpp:(.text+0x360): undefined reference to `mysql_stmt_bind_result'
mysql.cpp:(.text+0x37d): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x3a3): undefined reference to `mysql_stmt_fetch'
mysql.cpp:(.text+0x3ea): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x420): undefined reference to `mysql_stmt_error'
/tmp/ccaIe2WK.o: In function `mysqlUserWrite(void const*, unsigned long, unsigned long, _IO_FILE*)':
mysql.cpp:(.text+0x56f): undefined reference to `mysql_stmt_init'
mysql.cpp:(.text+0x596): undefined reference to `mysql_error'
mysql.cpp:(.text+0x5d8): undefined reference to `mysql_stmt_prepare'
mysql.cpp:(.text+0x5f5): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x6cb): undefined reference to `mysql_stmt_bind_param'
mysql.cpp:(.text+0x6e8): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x719): undefined reference to `mysql_stmt_execute'
mysql.cpp:(.text+0x731): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x747): undefined reference to `mysql_stmt_errno'
mysql.cpp:(.text+0x784): undefined reference to `mysql_stmt_affected_rows'
mysql.cpp:(.text+0x7c0): undefined reference to `mysql_stmt_init'
mysql.cpp:(.text+0x7e7): undefined reference to `mysql_error'
mysql.cpp:(.text+0x829): undefined reference to `mysql_stmt_prepare'
mysql.cpp:(.text+0x846): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x91c): undefined reference to `mysql_stmt_bind_param'
mysql.cpp:(.text+0x939): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x95f): undefined reference to `mysql_stmt_execute'
mysql.cpp:(.text+0x97c): undefined reference to `mysql_stmt_error'
mysql.cpp:(.text+0x9a2): undefined reference to `mysql_stmt_affected_rows'
mysql.cpp:(.text+0x9c7): undefined reference to `mysql_stmt_error'
/tmp/ccaIe2WK.o: In function `MySQLUserFilesCode()':
mysql.cpp:(.text+0xa09): undefined reference to `mysql_init'
mysql.cpp:(.text+0xa66): undefined reference to `mysql_real_connect'
mysql.cpp:(.text+0xa91): undefined reference to `mysql_error'
/tmp/ccaIe2WK.o: In function `MySQLInitCode(char*)':
mysql.cpp:(.text+0xb45): undefined reference to `mysql_init'
mysql.cpp:(.text+0xb72): undefined reference to `mysql_real_connect'
mysql.cpp:(.text+0xb8c): undefined reference to `mysql_error'
mysql.cpp:(.text+0xbc3): undefined reference to `mysql_query'
mysql.cpp:(.text+0xbd8): undefined reference to `mysql_error'
mysql.cpp:(.text+0xc0a): undefined reference to `mysql_use_result'
mysql.cpp:(.text+0xc24): undefined reference to `mysql_fetch_row'
mysql.cpp:(.text+0xc5b): undefined reference to `mysql_free_result'
mysql.cpp:(.text+0xc67): undefined reference to `mysql_close'
collect2: error: ld returned 1 exit status

解决方案

(executable.server) server: CFLAGS=-c -std=c++11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing executable.debugserver=../BINARIES/ChatScriptDebug debugserver: DEFINES+= -DLOCKUSERFILE=1 -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1 -DDEBUG -DEVSERVER=1 -DEVSERVER_FORK=1 debugserver: PGLOAD= -pthread debugserver: INCLUDEDIRS=-Ievserver debugserver: binary debugserver: EXECUTABLE=


(executable.debugserver) debugserver: CFLAGS=-c -std=c++11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing -g executable.standalone=../BINARIES/CS_LINUX standalone: DEFINES+= -DDISCARDSERVER=1 -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1 -DEVSERVER=1 -DEVSERVER_FORK=1 standalone: PGLOAD= -pthread standalone: INCLUDEDIRS=-Ievserver standalone: binary standalone: EXECUTABLE=


(executable.standalone) standalone: CFLAGS=-c -std=c++11 -Wall -funsigned-char -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing executable.pgserver=../BINARIES/ChatScriptpg pgserver: DEFINES+= -DLOCKUSERFILE=1 -DEVSERVER=1 -DEVSERVER_FORK=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1 pgserver: PGLOAD= -lpq -pthread pgserver: binary pgserver: EXECUTABLE=


这篇关于为什么我得到“未定义的引用...”我加入图书馆的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆