我正在關注here中的示例,我的代碼是相同的。在Linux中使用MYSQL.h編譯C++程序
當我將mysql_config --libs和mysql_config --cflags鍵入控制檯時,他解釋說,我得到與他顯示的相同的輸出。然而,當我嘗試使用編譯
g++ -o output-file $(mysql_config --cflags) test.cpp $(mysql_config --libs)
我得到的錯誤:
test.cpp:3:25: error: mysql.h: No such file or directory
test.cpp: In function âint main()â:
test.cpp:6: error: âMYSQLâ was not declared in this scope
test.cpp:6: error: âconnâ was not declared in this scope
test.cpp:7: error: âMYSQL_RESâ was not declared in this scope
test.cpp:7: error: âresâ was not declared in this scope
test.cpp:8: error: âMYSQL_ROWâ was not declared in this scope
test.cpp:8: error: expected `;' before ârowâ
test.cpp:13: error: âmysql_initâ was not declared in this scope
test.cpp:17: error: âmysql_real_connectâ was not declared in this scope
test.cpp:18: error: âmysql_errorâ was not declared in this scope
test.cpp:19: error: âexitâ was not declared in this scope
test.cpp:22: error: âmysql_queryâ was not declared in this scope
test.cpp:23: error: âmysql_errorâ was not declared in this scope
test.cpp:24: error: âexitâ was not declared in this scope
test.cpp:27: error: âmysql_use_resultâ was not declared in this scope
test.cpp:31: error: ârowâ was not declared in this scope
test.cpp:31: error: âmysql_fetch_rowâ was not declared in this scope
test.cpp:35: error: âmysql_free_resultâ was not declared in this scope
test.cpp:36: error: âmysql_closeâ was not declared in this scope
當我嘗試 'whereis mysql的' 它顯示在/ usr/bin中/ MySQL的,/ usr/lib中/ MySQL和/ usr/share/mysql,但我不確定mysql.h的確切位置。我正在工作的服務器的管理員說他安裝了MySQL,我確實可以使用phpMyAdmin創建/操作表。
另外,請給我關於這個特定問題的建議。我知道MySQL的C++包裝,但我現在只想使用C API。謝謝!
是的,我相信你是對的。經過一段時間的捕魚後,似乎我沒有正確的軟件包來開發使用MySQL的應用程序。我有點擔心自己安裝它們,儘管服務器的管理員在那裏安裝了MySQL。雖然,我確實有'管理員'訪問服務器,但我不知道添加它們是否有任何潛在的危害。 – Aaron 2012-07-14 18:38:07
@Aaron您需要在服務器上安裝libmysqlclient,但需要在您正在開發的機器上使用devel頭文件。 – fbafelipe 2012-07-14 18:43:02
哦,我明白了。 devel頭文件只是在本地編譯應用程序,然後我可以將它們上傳到服務器以正確運行? – Aaron 2012-07-14 19:24:09