0

The code that follows works perfectly in Windows but not on Red Hat Enterprise Linux Server release 5.9 (Tikanga).

I first had to install gcc44-c++.x86_64, which already solved some issues.

But when I tried to compile my C++ code via g++44 -std=c++0x MyProgram.c -lpthread -o MyProgram (I am also working with threads) I got confronted with following message:

/tmp/ccbL2a6z.o: In function `writeLog(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
MyProgram.c:(.text+0x1eb): undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
collect2: ld returned 1 exit status

This is the code who might cause trouble (only extract of the whole code):

#define _GLIBCXX_USE_NANOSLEEP 
#include <iostream>
#include <chrono>
#include <thread>
#include <string>
#include <stdio.h>
#include <vector>
#include <fstream> 

//function to create timestamp
const std::string getTimestamp() {
    time_t now = time(0);
    struct tm tstruct = *localtime(&now);
    char timestamp[80];
    strftime(timestamp, sizeof(timestamp), "%Y-%m-%d.%X", &tstruct);
    return timestamp;
}

//function to write into logfile
void writeLog(std::string output){
    std::ofstream logfile;
    logfile.open(logpath, std::ios::out | std::ios::app);
    logfile << output << "\n";
    logfile.close();
}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Incanus
  • 389
  • 1
  • 4
  • 16

0 Answers0