LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Executing .o-Files (dont know their name) (https://www.linuxquestions.org/questions/linux-newbie-8/executing-o-files-dont-know-their-name-641653/)

garlic 05-12-2008 09:48 AM

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?

bigrigdriver 05-12-2008 10:23 AM

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.

garlic 05-12-2008 10:32 AM

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!

datopdog 05-12-2008 10:43 AM

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.

garlic 05-12-2008 10:55 AM

And how can I do that?

colucix 05-12-2008 11:09 AM

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?

garlic 05-12-2008 11:28 AM

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?

garlic 05-12-2008 12:04 PM

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.

michaelk 05-12-2008 12:42 PM

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

chrism01 05-12-2008 05:59 PM

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


All times are GMT -5. The time now is 05:45 PM.