1

我有一个程序,该程序具有使用 libxl 库导出 xls 文件的功能。在我的主程序中,我不调用该函数。在执行导出函数的 cpp 中,如果该函数被注释,则程序正常运行并在控制台上打印一些东西。如果我从注释中取出该函数,程序将立即终止而没有给我一个错误。每次我尝试使用调试时,我都会收到此错误

C:Documents and SettingsplatonasWorkspace Eclipse for CHeliostatValidationsrcHeliostatValidation.cpp

应该是

C:/HeliostatValidation/src/HeliostatValidation.cpp

我的基本问题是,由于我没有调用该函数,为什么我会因为该函数未使用而出现错误。

主文件

#include <iostream>
using namespace std;
#include "ValidationController.h"
#include "SettingsHandler.h"


int main() {
SettingsHandler shObj;
shObj.readFile();
shObj.setVariables();
shObj.printSettings();
ValidationController vcObj;

vcObj.calcContrBatch(2013,9,26,8,47,47,Sun::OneYear,Sun::ArcsinMode,Sun::East);


vcObj.printData(vcObj.dataValues);
//  vcObj.exportData(vcObj.dataValues,"file");

return 0;
}

和具有该功能的cpp

#include <iostream>
using namespace std;
#include "ValidationController.h"
#include <array>
#include "NTP.h"
#include "DayNumber.h"
#include "Heliostat.h"
#include "Data.h"
#include <vector>
#include <fstream>
#include <iomanip>
#include "libxl.h"
using namespace libxl;

 void ValidationController::exportData(const vector<Data>& dataVector,string nameOfFile) {

    Book *book = xlCreateBook();
    if(book){
        Sheet *sheet=book->addSheet("Sheet1");
        if(sheet){
            sheet->writeStr(2,2,"Year");
            sheet->writeStr(2,3,"Month");
            sheet->writeStr(2,4,"Day");
            sheet->writeStr(2,5,"DayOfWeek");
            sheet->writeStr(2,6,"LctHour");
            sheet->writeStr(2,7,"Minutes");
            sheet->writeStr(2,8,"Seconds");
            sheet->writeStr(2,9,"TimeDec");
            sheet->writeStr(2,10,"Sun's Elevation");
            sheet->writeStr(2,11,"Sun's Azimuth");
            sheet->writeStr(2,12,"Helio's Pitch");
            sheet->writeStr(2,13,"Helio's Azimuth");

//          int lineMorphing=dataVector.at(0).getDayOfWeek();
//
//          for (unsigned int i=0,m=3;i<dataVector.size();i++,m++){
//              if(dataVector.at(i).getDayOfWeek()!=lineMorphing){
//                  lineMorphing=dataVector.at(i).getDayOfWeek();
//                  m++;
//              }
//              int k=0;
//              sheet->writeNum(m,++k,dataVector.at(i).getYear());
//              sheet->writeNum(m,++k,dataVector.at(i).getMonth());
//              sheet->writeNum(m,++k,dataVector.at(i).getDay());
//              sheet->writeNum(m,++k,dataVector.at(i).getDayOfWeek());
//              sheet->writeNum(m,++k,dataVector.at(i).getHour());
//              sheet->writeNum(m,++k,dataVector.at(i).getMinutes());
//              sheet->writeNum(m,++k,dataVector.at(i).getSeconds());
//              sheet->writeNum(m,++k,dataVector.at(i).getTimeInDecimal());
//              sheet->writeNum(m,++k,dataVector.at(i).getSunsPitch());
//              sheet->writeNum(m,++k,dataVector.at(i).getSunsAzimuth());
//              sheet->writeNum(m,++k,dataVector.at(i).getHelioPitch());
//              sheet->writeNum(m,++k,dataVector.at(i).getHelioAzimuth());
//
//          }
//
        }
        nameOfFile.append(".xls");
        const char* fileName=nameOfFile.c_str();
        book->save(fileName);
        book->release();

    }else{
        cout <<"error on book"<<endl;
    }
}

我注意到像“sheet1”这样的每个字符串在like之前都有一个L

Sheet *sheet=book->addSheet(L"Sheet1");

在官方示例中。至于库,我已经转到 Properties-->Build C/C++ -->Settings -->Linker MinGW(在选项卡上)-->libraries 并且我已经添加了路径和名称没有扩展名 .lib 的库我也将 libxl 文件中名为“include cpp”的文件夹的路径包含在编译器中,这样程序就可以看到头文件。我已经阅读了一些关于在 Eclipse 中从溢出中添加库的帖子。

再次抱歉主要问题,为什么 main 中未调用的函数负责终止程序。

4

0 回答 0