Делаю два сpp файла, чтобы собрать из них библиотеку с помощью makefile в LINUX
Мне нужно записать значения переменных discretX, discretY из function1.cpp в function2.cpp
Как это сделать?
function.h
struct InfaboutChanell
{
int chanellcount;
int analogChanell;
int discretChanell;
};
void writeCfgFile ();
void writeBinaryFile();
function1.cpp
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include "functions.h"
using namespace std;
struct Station station;
void writeCfgFile(){
ofstream file("fileConfiguration.cfg");
//The information about count of channels
struct InfaboutChanell infaboutChanell;
infaboutChanell.chanellcount=14;
const int analogX =6;
infaboutChanell.analogChanell=analogX;
const int discretX=8;
infaboutChanell.discretChanell=discretX;
//проверка на сумму каналов
int sum;
sum = infaboutChanell.analogChanell+infaboutChanell.discretChanell;
if (sum != infaboutChanell.chanellcount)
{
cout << "Please enter correct count of channels: " <<'\n';
}
file<<infaboutChanell.chanellcount<<","<<infaboutChanell.analogChanell<<"A"<<","<<infaboutChanell.discretChanell<<"D"<<"\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;
struct InfaboutChanell aboutchanell;
void writeBinaryFile(){
// Create Binary file
fstream binary_file("D:\\Struct\\Struct\\ComtradeFormat\\fileConfiguration.dat",ios::out|ios::binary|ios::app);
if(!binary_file)
{
cout << "Cannot open file.\n";
return 1;
}
int i=0;
int n=0;
int timestamp =0;
for (i=0; i<=generalinformation.ensamp; i++){
n = i+1;
binary_file.write((char *) &n, sizeof n);
timestamp = i*1000;
binary_file.write((char *) ×tamp, sizeof timestamp);
// Value of analog channels
short analogValue<b> [analogX]</b>;
for(int i=0; i<analogX; i++)
analogValue[i] = rand() % 20000 - 10000;
binary_file.write((char *) &analogValue, sizeof analogValue);
unsigned __int16 m_bytesCount = 0;
m_bytesCount = discretX / 16;
if (discretX % 16){
m_bytesCount++;
}
int ChValue<b> [discretX]</b> = {1, 1, 1, 0, 0, 0, 0, 0};
for(int i = 0; i < discretX; ++i)
{
if(ChValue[i] == 1)
m_bytesCount |= 1 << i;
}
binary_file.write((char *) &m_bytesCount, sizeof m_bytesCount);
}
binary_file.close();