求助!C++ 实践之引入外部头文件失败
2017-08-07 17:49
465 查看
摘要: 保持对技术的热忱
本来想整合一下,这两天学习的内容,发布一个具备读写ini、写日志的demo。谁想到新的问题出来,按照原思路。创建common.cpp 将一些工具方法归纳其中。demo1.cpp通过引入common.h文件 实现方法的调用。
关键代码如下:
common.cpp:
commom.h:
demo1.cpp:
编译时 提示如下错误信息:
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
从错误信息中分析,应该是头文件没有起作用。可是参考相关一些相关头文件的使用。未发现问题之所在。还请哪位大侠给予帮助
本来想整合一下,这两天学习的内容,发布一个具备读写ini、写日志的demo。谁想到新的问题出来,按照原思路。创建common.cpp 将一些工具方法归纳其中。demo1.cpp通过引入common.h文件 实现方法的调用。
关键代码如下:
common.cpp:
/** * 这是一个 工具类的对象 */ #include <windows.h> #include <string.h> #define INI_FILE_PATH ".//study.ini" #define LOG_FILE_NAME "studylog" #define LOG_VALUE_MAXSIZE 80 void 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
从错误信息中分析,应该是头文件没有起作用。可是参考相关一些相关头文件的使用。未发现问题之所在。还请哪位大侠给予帮助
相关文章推荐
- 求助!C++ 实践之引入外部头文件失败
- C++ 实践之引入外部头文件
- C++引入外部txt文件内容的方法
- 引入外部css文件时最好加上type属性,否则有可能引入失败
- vue2引入外部js文件(以hammer.js为例)
- VS2010 C++编译报错LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- VS2010 C++编译报错LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 关于外部引入jQuery代码文件不执行解决方案
- 在HTML中引入外部文件CSS和JS的方法
- MyBatis之全局配置文件(Configuration XML)之引入外部配置文件(properties)
- 在html中引入外部js文件,并调用带参函数
- mybatis在关联映射中,引入外部xml文件中定义的对象
- C++激活外部文件或程序
- springboot干货——(八)springboot引入外部xml配置文件
- C++外部程序修改exe文件属性信息的版本信息
- Android Studio下JNI编程(引入外部或AS自行编译so文件)
- Jsp中引入css等外部文件路径问题
- karaf中利用Bundle引入外部log4j配置文件
- Flash中类的编写及引入外部as文件的方式
- tp3.2/thinkphp3.2引入外部类文件/.php文件总结