求助!C++ 實踐之引入外部標頭檔失敗

來源:互聯網
上載者:User

標籤:c++ 標頭檔引入

 本來想整合一下,這兩天學習的內容,發布一個具備讀寫ini、寫日誌的demo。誰想到新的問題出來,按照原思路。建立common.cpp 將一些工具方法歸納其中。demo1.cpp通過引入common.h檔案 實現方法的調用。

    650) this.width=650;" src="https://static.oschina.net/uploads/space/2017/0803/164924_4uvq_3435444.png" style="width:189px;height:199px;" />

    關鍵代碼如下:

    common.cpp:

    

/** * 這是一個 工具類的對象 */#include <windows.h>#include <string.h>#define INI_FILE_PATH ".//study.ini"#define LOG_FILE_NAME "studylog"#define LOG_VALUE_MAXSIZE 80void readIniValue(char* lable,char* anchor,char* iniValue){  char buffer[LOG_VALUE_MAXSIZE];  GetPrivateProfileString(lable, anchor, NULL, buffer, sizeof(buffer), INI_FILE_PATH );//讀取 設定檔 需要引入 <windows.h>iniValue = new char[sizeof(buffer)+1];strcpy(iniValue,buffer);}

    commom.h:

  #ifndef COMMON  #define COMMON  /**   * 讀取設定檔   * @param  label    記錄檔 標籤   * @param  anchor   記錄檔 錨點   * @param  iniValue 讀取到日誌的值   */   void readIniValue(char* lable,char* anchor,char* iniValue);  #endif

    demo1.cpp:

/*這個案例 用於說明C++ 讀取設定檔 寫入記錄檔2017-08-03 *//** * 這個案例 用於說明C++ 讀取設定檔 寫入記錄檔 * @param  argc [description] * @param  argv [description] * @return      [description] * @createTime 2017-08-03 */ #include "common.h"#include <iostream>#include <windows.h>// 讀取ini檔案 引入 必要檔案using namespace std;//定義全域變數// #define INI_FILE_PATH ".//study.ini"// #define LOG_FILE_NAME "studylog.txt"// void readIniValue(char* lable,char* anchor,char* iniValue){//   char buffer[80];//   GetPrivateProfileString(lable, anchor, NULL, buffer, sizeof(buffer), INI_FILE_PATH );//讀取 設定檔 需要引入 <windows.h>//  std::cout << buffer << ‘\n‘;////// iniValue = new char[sizeof(buffer)+1];// strcpy(iniValue,buffer);//// }int main() { // 整理 讀取 配置ini 設定檔 // char buffer[80]; // GetPrivateProfileString("Log", "Level", NULL, buffer, sizeof(buffer), INI_FILE_PATH );//讀取 設定檔 需要引入 <windows.h> // cout<<buffer; char* iniValue=0; char* lable="Log"; char* anchor="Level"; //lable="Log"; //anchor="Level"; readIniValue(lable,anchor,iniValue); std::cout << iniValue << ‘\n‘;  return 0;}


編譯時間 提示如下錯誤資訊:

demo1.cpp: In function ‘int main()‘:

demo1.cpp:38:14: warning: deprecated conversion from string constant to ‘char*‘ [-Wwrite-strings]

demo1.cpp:39:15: warning: deprecated conversion from string constant to ‘char*‘ [-Wwrite-strings]

C:\Users\ADMINI~1\AppData\Local\Temp\cclOz7l9.o:demo1.cpp:(.text+0x3e): undefined reference to `readIniValue(char*, char*, char*)‘

collect2.exe: error: ld returned 1 exit status

從錯誤資訊中分析,應該是標頭檔沒有起作用。可是參考相關一些相關標頭檔的使用。未發現問題之所在。還請哪位大俠給予協助


本文出自 “洛山紅茶的成長” 部落格,請務必保留此出處http://85608547.blog.51cto.com/2093443/1953383

求助!C++ 實踐之引入外部標頭檔失敗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.