2016-02-26 76 views
0

我試圖編譯使用VisualGDB和交叉編譯樹莓PI簡單的C++程序。我在本教程http://visualgdb.com/tutorials/raspberry/wiringPi/所做的一切,併成功地運行示例閃爍的LED應用,使一切似乎進行配置確定。未定義參考到MySQL,同時使用交叉編譯和VisualGDB

現在我想添加一些mysql支持來記錄更改並閱讀一些配置信息。

#include <wiringPi.h> 
#include <mysql/mysql.h> 

int main(int argc, char *argv[]) 
{ 
    wiringPiSetup(); 

    MYSQL *mysql1 = mysql_init(NULL); 


} 

可惜的是,我得到的連接錯誤:

'NULL' was not declared in this scope 

我想包括

#include <mysql/my_global.h> 

頭,所以NULL不再是未申報的,但另一個錯誤顯示:

error VGDB1000: undefined reference to `mysql_init' 

我做了什麼錯?

編輯我的設置

新增截圖。 TBH我不知道GCC很好......也許這就是爲什麼我使用VisualGDB;)

enter image description here

我嘗試添加附加這LDFLAGS:

`mysql_config --cflags` `mysql_config --libs` 

但它我得到一個錯誤:

Tool arguments: -Wl,--start-group "C:\Users\Marek\AppData\Local\Temp\/VisualGDB_ToolchainTestProgram.o" -o "C:\Users\Marek\AppData\Local\Temp\/VisualGDB_ToolchainTestProgram" -Wl,-gc-sections `mysql_config --cflags` `mysql_config --libs` -lpthread -lwiringPi -Wl,--end-group 
arm-linux-gnueabihf-gcc.exe: error: `mysql_config: No such file or directory 
arm-linux-gnueabihf-gcc.exe: error: `mysql_config: No such file or directory 

回答

1

好吧,我設法解決這個問題。我發現非常有用的技巧在這裏:https://sysprogs.com/w/forums/topic/include-mysqlmysql-h-errorundefined-reference-to/

You need to add the MySQL library to the ‘libraries’ setting in the VisualGDB Project Properties. Specify the name without the ‘lib’ prefix and ‘.a’ suffix. E.g. if the library name is libmysql.a, simply specify ‘mysql’ in the ‘libraries’ field. You may also need to put extern 「C」 around the include file if it does not contain it.

我嘗試添加「MySQL的」以庫名部分,但正確的名稱是的mysql

沒有必要使用extern或添加LDFLAGS。

所以每當你要添加新庫,檢查是否有您的庫目錄中正確的文件。

謝謝你的意見,他們指示我到這個解決方案。

-1

NULLstdio.h定義的,所以你只需要

#include <stdio.h> 

#include <iostream> 

或自己定義:

#define NULL 0 

關於undefined reference to 'mysql_init',它不被定義爲NULL引起的。

這個錯誤是從鏈接步驟,所以這意味着當你使NULL有效(這是從編譯步驟導致的錯誤)從鏈接步驟的錯誤將顯示。

請仔細檢查頭文件中的mysql_init的定義。

+1

我認爲它宣告內的某處作爲my_global.h包括文件解決了NULL的問題,但會導致另一個與mysql_init ... – Mark

+0

@Niall不,它是一個連接錯誤。 – EJP

+1

謝謝您的意見。據我所知,交叉編譯器在本地編譯程序,然後將可執行文件上傳到遠程設備。我不得不同步與當地覆盆子庫,他們都發現我的C:SysGCC文件夾/驅動器。所以我敢肯定,這些錯誤來自接頭,無法找到儘管Visual Studio中需要的庫/ VisualGDB插件正確定位它們99%。我已經編輯了我的問題,請看看。 – Mark