LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-12-2008, 10:48 AM   #1
garlic
LQ Newbie
 
Registered: May 2008
Posts: 5

Rep: Reputation: 0
Executing .o-Files (dont know their name)


Hi everybody!

I hope you can help me. I don't know how to discribe this but I am going to try:
I have a fortran file (.for) and a compiled (.o) version of the same program. The program is just a program that takes 2 parameters and returns a number.
This should be called in console (bash) like "program.o(2.4,3.5)".
I don't want to use a compiler.
How can this be done?

Thanks for any hint!

Edit: I just recognized that there is a .a-File with the .o-Files inside. Is this the file to call?

Last edited by garlic; 05-12-2008 at 10:59 AM.
 
Old 05-12-2008, 11:23 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Quote:
The program is just a program that takes 2 parameters and returns a number.
This should be called in console (bash) like "program.o(2.4,3.5)".
I don't want to use a compiler.
How can this be done?
Files with the .o extension are object files (already compiled). You can probably run the program by cd to the directory that has the program and run it like this: program.o 2.4 3.5 (the inputs are seperated by a space).

Or, from anywhere in the directory tree, give the full path to the program followed by the inputs.
 
Old 05-12-2008, 11:32 AM   #3
garlic
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks, but that doesn't work, I get "command not found" error in bash.
Can I call the Archive (.a-file) with the program inside (as .o-File)?
Is there a good doc/howto for .a-files to use from bash?
Thanks!
 
Old 05-12-2008, 11:43 AM   #4
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
I dont think you can run an object file the file has to be linked and an ELF executable created before you can run it.
 
Old 05-12-2008, 11:55 AM   #5
garlic
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
And how can I do that?
 
Old 05-12-2008, 12:09 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You should use a linker (see man ld for details) and specify the location of the fortran libraries and all the shared libraries used. Better to do the compilation again with your fortran compiler, since it takes care of this last step (linking object files and shared libraries together) automatically, unless you specify the -c option. Anyway, how did you obtain a .o file?
 
Old 05-12-2008, 12:28 PM   #7
garlic
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
The compiling is not the problem. I just wanted to know how to use just the .o files or the static library (thats how the a-file is called) from out the bash. What if the .for files are missing? Do I really have to run a compiler again? Is there no other way?
 
Old 05-12-2008, 01:04 PM   #8
garlic
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
I am playing with the thought to open up a new thread with the title: Using programs inside static libraries from out bash.
I had no idea before opening this thread that the .a file is such a library with object files inside.
I am sorry that this is a bad approach but I had also no idea where to start to ask.
Thanks for helping me!

Edit: And I read through the ld manual, but still dont know what to do with that.

Last edited by garlic; 05-12-2008 at 01:05 PM.
 
Old 05-12-2008, 01:42 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,950

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
What Fortran complier are you using?
Typically if you want to compile hello.for:

g77 hello.for your executable file name will be named a.out
g77 -o hello hello.for your executable file will be named hello (no extension required)
g77 -c hello.for will create the object file hello.o

To run the program assuming it is not in the users path environment type in:
./hello
 
Old 05-12-2008, 06:59 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Normally its

prog.for - src file
prog.o - compiled object file: note you can't run this
prog (or prog.exe on some OSes) runnable exe after 'linking' the object file(s) and any reqd libs
stuff.a - static lib file to be linked to your progs as needed

Generally most compilers default to compiling and linking in one go, unless you specify compile only. YMMV

To run it, specify path & name
/home/me/prog
or (if I'm in that dir already)
./prog

Last edited by chrism01; 05-12-2008 at 07:01 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to prevent apache from executing certain files imi@tux Linux - Server 3 09-21-2007 01:26 AM
Executing bin files Squiddy Slackware 2 11-07-2003 03:11 AM
help executing files safil Linux - Newbie 7 09-03-2003 02:51 AM
Executing .bin files klmn1 Linux - Software 2 06-06-2003 03:04 AM
executing files jiggaracci Linux - General 8 10-13-2002 02:38 PM


All times are GMT -5. The time now is 06:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration