LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2007, 02:42 AM   #1
SJD
LQ Newbie
 
Registered: Jan 2007
Posts: 25

Rep: Reputation: 15
GCC 4.1.2 ofstream problem


Hi all,

I recently upgraded from Slackware 11 to 12 and with it GCC from 3.4.6 to 4.1.2. I am now trying to compile and run a program I have written which runs perfectly well under slackware 11 but which compiles fine, but will not run under 12. I get a halt in the execution of the code when I try to use ofstream. I have checked that the file exists and no handles are open to it and that the permissions for the file are correct. The code compiles so I know that I have not missed a #include (and it works on GCC 3.4.6). This is driving me nuts!

I alos have another problem (with the same code). I have an executable and a set of shared libraries. If I try to load a library from the executable all is well. If I try to load a library from another library the code crashes. Again this did used to work on GCC 3.4.6.

Does anyone have any ideas?

Thanks for your help,

Steve
 
Old 08-03-2007, 03:37 AM   #2
SCerovec
Senior Member
 
Registered: Oct 2006
Location: Cp6uja
Distribution: Slackware on x86 and arm
Posts: 2,471
Blog Entries: 2

Rep: Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980
Is there a Changelog for gcc? It might have hints?
 
Old 08-03-2007, 03:47 AM   #3
SJD
LQ Newbie
 
Registered: Jan 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Thanks for your reply. I have checked the changelog and I could see no mention of altering anything to do with ofstream (or associated functions). I have also searched on the internet for this problem and there have been a few occurences of people having difficulties with associated ofstream functions with GCC 4.1.2, but no-one seems to have found an answer and they all are stopping the code from compiling, where as mine compiles fine, just won't run!
 
Old 08-03-2007, 12:07 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Is it a 100% C++ program? Can you isolate the problem so that it happens with a short piece of code?
ta0kira
 
Old 08-06-2007, 02:04 AM   #5
SJD
LQ Newbie
 
Registered: Jan 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Hi ta0kira,

Thnaks for your reply. Unfortunately this seems to be an intermittent problem so I get different results from different runs through of the same code! I am currently looking at the file system I am using to see if this is the problem.

I also have another issue with the dlopen function. This does fail repeatedly if I call it from a shared library. If I call it from an exe then it succeeds without a problem. I've checked all of the obvious things like making sure the library exists, permissions and file path and they are all correct. I am using the same code to load the libraries from either the shared library or the exe. This used to work no problem before I upgraded my OS!

Thanks for your time,

Steve
 
Old 08-06-2007, 02:39 AM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Can you post the code?
ta0kira
 
Old 08-06-2007, 04:14 AM   #7
SJD
LQ Newbie
 
Registered: Jan 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Here's my code for loading a shared library:

/////////////////////////////////////////////////////////////////////////////////////
//Method : Load
//Description : This function loads a module from the host.
//Input Params : ModuleName - The name of the module to load.
//Output Params : None
//Return : true if the module was loaded false otherwise.
/////////////////////////////////////////////////////////////////////////////////////
bool Load(const string& ModuleName)
{
bool success = true;

string tempModName = tempLibPath + ModuleName;

void* handle = dlopen((char*)tempModName.c_str(), RTLD_NOW | RTLD_GLOBAL);
if (!handle)
{
success = false;
}

return success;
}

The code fails on the dlopen line. It never gets past it, there is no error code generated but if I put a printf statement on the following line it never gets printed to the terminal. I am using this code to load successfully from an exe, it only fails from being called from a shared library.

Thanks for your help,

Steve
 
Old 08-06-2007, 10:51 AM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
After the handle open fails, printf dlerror with a newline. The newline will force the buffer to flush. If you don't get a message but it still fails, you're probably getting a signal. Have main return 0 for success and 1 for error. If it's an abnormal termination then the return will be some other number. My guess is that the library isn't in the library path. If it's local to the directory, try placing ./ before it. Otherwise libdl will look in the library path.
ta0kira
 
Old 08-08-2007, 09:56 AM   #9
SJD
LQ Newbie
 
Registered: Jan 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Hi ta0kira,

Thanks again for your reply. I think I have now got to the bottom of this problem. I have been using a USB booting build of Slackware 12 made using the Linux-Live scripts. These utilise a new filesystem AUFS and when I move my code from AUFS to an ext2fs partioned part of my flash drive all is (almost) well! I seem to be getting lots of problems with AUFS with reading and writing to files as well as loading libraries, so I shall move a fresh set of source code directly to my ext2 partition and see how it goes.

Thanks for your help,

Steve
 
Old 11-14-2008, 06:20 AM   #10
Pranay1711
LQ Newbie
 
Registered: May 2008
Posts: 8

Rep: Reputation: 0
I get a similar problem where ofstream hangs when called from the thread on RHEL5. RHEL3 it works correctly.
Has any faced similar problems?
please advise.... we are in process of porting our code and got stuck on this
 
Old 11-14-2008, 07:57 AM   #11
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by Pranay1711 View Post
I get a similar problem where ofstream hangs when called from the thread on RHEL5. RHEL3 it works correctly.
Has any faced similar problems?
please advise.... we are in process of porting our code and got stuck on this
Please start another thread and post information about the problem and circumstances in which you have the problem. As of now all we know is "ofstream hangs" on "RHEL5", that is not enough information to help in any meaningful way.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ofstream & ifstream simple (i think) problem nadroj Programming 2 04-25-2006 10:28 PM
not able to get fd of ofstream using stdio_filebuf Devika Linux - General 0 03-27-2005 11:33 PM
ofstream and inheritence phoenix7 Programming 1 01-02-2005 02:52 AM
ofstream problem cgifalcon Linux - Software 2 10-19-2003 12:00 PM
c++ ofstream -> FILE * ChimpFace9000 Programming 1 08-25-2002 04:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration