K
K
kytcenochka2018-05-02 10:27:05
linux
kytcenochka, 2018-05-02 10:27:05

Errors when compiling a C++ project on linux (makefile)?

I wrote a program in visual studio 2008, everything compiles, two files are written.
But the task is to build the .so library on Linux, makefile, I'm trying to compile a lot of errors.
function.h

int const GlobalVariableCountCh = 14;
int const GlobalVariableACh = 6;
int const GlobalVariableDCh = 8;
 
struct Station
{ 
    std::string station_name; 
    std::string rec_dew; 
    std::string year;
};
 
struct InfAnalogChanel
{ 
    int id;
    std::string chanell_id;
    std:: string ph;
    std::string ccmb;
    std::string UU;
    float a;
    double b;
    double skew;
    double min;
    double max;
    double Primery;
    double Secondary;
    std::string SP;  
};
struct InfDiscretChanel
{
    int DN;
    std::string ch_id;
    std::string ph;
    std::string ccmb;
    int y;
};
 
struct GeneralInf
{
    int ifone;
    int nrates;
    int samp;
    int ensamp;
 
};
 
 
void writeCfgFile (); 
void writeBinaryFile();

function1.cpp
//#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "functions.h"
using namespace std;
 
struct Station station;
 
 
       void writeCfgFile(){
       station.station_name="Strathmore 251 kV";
       station.rec_dew = "1";
       station.year="2001";
       ofstream file("fileConfiguration.cfg");
       file<<station.station_name<<","<<station.rec_dew<<","<<station.year<<"\n";
      
     
       //The information about analog channels
 
       vector<InfAnalogChanel> s;
       InfAnalogChanel a;
       InfAnalogChanel b;
    
 
 
       a.id=1;
       a.chanell_id="ток ф А";
       a.ph="";
       a.ccmb="";
       a.UU="A";
       a.a=1.290489E-01;
       a.b=0;
       a.skew=0;
       a.min=-32767;
       a.max=32767;
       a.Primery=3000.00000000;
       a.Secondary=1.00000000;
       a.SP="P";
 
       b.id=2;
       b.chanell_id="ток В";
       b.ph="";
       b.ccmb="";
       b.UU="A";
       b.a=5.139708E-02;
       b.b=0;
       b.skew=0;
       b.min=-32767;
       b.max=32767;
       b.Primery=3000.00000000;
       b.Secondary=1.00000000;
       b.SP="P";

       s.push_back(a);
       s.push_back(b);
      
 
       for(int i=0;i<s.size();++i)
           file<<s[i].id<<","<<s[i].chanell_id<<","<<s[i].ph<<","<<s[i].ccmb<<","<<s[i].UU<<","<<s[i].a<<","<<s[i].b<<","<<s[i].skew<<
           ","<<s[i].min<<","<<s[i].max<<","<<s[i].Primery<<","<<s[i].Secondary<<","<<s[i].SP<<"\n";
      
       //The information about discret chanells
       vector<InfDiscretChanel> discret;
       InfDiscretChanel first;
       InfDiscretChanel sec;
   
 
       first.DN=1;
       first.ch_id = "Раб МТЗ";
       first.ph="";
       first.ccmb="";
       first.y=0;
 
       sec.DN=2;
       sec.ch_id = "3_3";
       sec.ph="";
       sec.ccmb="";
       sec.y=0;
 
     
       discret.push_back(first);
       discret.push_back(sec);
 
       for(int i=0;i<discret.size();++i)
           file<<discret[i].DN<<","<<discret[i].ch_id<<","<<discret[i].ph<<","<<discret[i].ccmb<<","<<discret[i].y<<"\n";
 
 
       //General information
       struct GeneralInf generalinformation;
       generalinformation.ifone = 50;
       generalinformation.nrates = 1;
       generalinformation.samp = 1000;
       generalinformation.ensamp = 5107;
 
       file << generalinformation.ifone << "\n" << generalinformation.nrates << "\n" << generalinformation.samp << ","
           << generalinformation.ensamp << "\n";
 
       struct DateTime {
           int dd;
           int mm; 
           int yyyy;
           int hh;
           int min;
           float sec;
           string type;
           int nfile;
       };
 
       vector<DateTime> time;
       DateTime samp;
       DateTime endsamp;
 
       samp.dd = 24;
       samp.mm=10;
       samp.yyyy=2017;
       samp.hh=10;
       samp.min=55;
       samp.sec=14.546459;
       endsamp.dd = 24;
       endsamp.mm=10;
       endsamp.yyyy=2017;
       endsamp.hh=10;
       endsamp.min =55;
       endsamp.sec =14.647162;
 
       time.push_back(samp);
       time.push_back(endsamp);
       for(int i=0;i<time.size();++i)
           file<<time[i].dd<<"/"<<time[i].mm<<"/"<<time[i].yyyy<<","<<time[i].hh<<":"<<time[i].min<<":"<<time[i].sec<<"\n";
 
       DateTime type;
       type.type = "BINARY";
       DateTime nnfile;
       nnfile.nfile =1;
       file<<type.type<< "\n"<< nnfile.nfile << "\n";
       file.close();
}

function2.cpp
//#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "functions.h"
using namespace std;
 
struct GeneralInf inf;
 
 
 
 
void writeBinaryFile(){
    fstream binary_file("fileConfiguration.dat",ios::out|ios::binary|ios::app);
    int i=0;
    int n=0;
    int timestamp =0;
    
 
    for (i=0; i<=inf.ensamp; i++){
        n = i+1;
        binary_file.write((char *) &n, sizeof n);
        timestamp = i*1000;
        binary_file.write((char *) &timestamp, sizeof timestamp);  
 
        // Value of analog channels
        short analogValue  [GlobalVariableACh];
        for(int i=0; i<GlobalVariableACh; i++)
 
            analogValue[i] = rand() % 20000 - 10000;
        binary_file.write((char *) &analogValue, sizeof analogValue);
 
        unsigned __int16 m_bytesCount = 0;
        m_bytesCount = GlobalVariableDCh / 16;
        if (GlobalVariableDCh % 16){
            m_bytesCount++;
        }
 
        int ChValue [GlobalVariableDCh] = {1, 1, 1, 0, 0, 0, 0, 0};
 
        for(int i = 0; i < GlobalVariableDCh; ++i)
        {
            if(ChValue[i] == 1)
                m_bytesCount |= 1 << i;
        }
 
        binary_file.write((char *) &m_bytesCount, sizeof m_bytesCount);
    }
 
    binary_file.close();

}

main.cpp
<code lang="cpp">
// MyDll.cpp : Defines the entry point for the console application.
//
 
//#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include "functions.h"
using namespace std;
 
 
int main()
{

}
</code>

makefile
all:
g++ main.cpp function1.cpp function2.cpp -o hello

Ошибки при компиляции
function1.cpp: В функции «void writeCfgFile()»:
function1.cpp:219:23: ошибка: template argument for «template<class> class std::allocator» uses local type «writeCfgFile():ateTime»
vector<DateTime> time;
^
function1.cpp:219:23: ошибка: при конкретизации «template<class> class std::allocator»
function1.cpp:219:23: ошибка: некорректный аргумент шаблона 2
function1.cpp:219:29: ошибка: invalid type in declaration before «;» token
vector<DateTime> time;
^
function1.cpp:236:13: ошибка: запрос элемента «push_back» в «time», имеющего не классовый тип «int»
time.push_back(samp);
^
function1.cpp:239:41: ошибка: некорректные типы «int[int]» для индекса массива
file<<time[i].dd<<"/"<<time[i].mm<<"/"<<time[i].yyyy<<","<<time[i].hh<<":"<<time[i].min<<":"<<time[i].sec<<"\n";
^
function2.cpp: В функции «void writeBinaryFile()»:
function2.cpp:31:35: ошибка: нет декларации «rand» в этой области видимости
analogValue[i] = rand() % 20000 - 10000;
^
function2.cpp:34:26: ошибка: expected initializer before «m_bytesCount»
unsigned __int16 m_bytesCount = 0;
function2.cpp:35:9: ошибка: нет декларации «m_bytesCount» в этой области видимости
m_bytesCount = GlobalVariableDCh / 16;
makefile:2: ошибка выполнения рецепта для цели «all»

Помогите разобраться! не работала в linux.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
terrier, 2018-05-02
@terrier

vector<DateTime> time;
Prior to C++11, it was not possible to use local types in template parameters. Visual Studio, apparently, substitutes for you in the project build parameters "build with the latest standard" or something like that. Under linux, put -std=c++11 in the compile options in the makefile, this will enable support for features from this standard.
(The following errors are just due to the fact that we failed to correctly declare this vector).
rand is declared in the cstdlib header to include

unsigned __int16 m_bytesCount = 0;
function2.cpp:35:9: error: no "m_bytesCount" declaration in this scope
__int16 is a non-cross platform way to declare fixed width types. Cross platform - connect cstdint and use int16_t etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question