求助!C++ 实践之引入外部头文件失败

   本来想整合一下,这两天学习的内容,发布一个具备读写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

从错误信息中分析,应该是头文件没有起作用。可是参考相关一些相关头文件的使用。未发现问题之所在。还请哪位大侠给予帮助

转载于:https://my.oschina.net/u/3435444/blog/1501522

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值