what to do with .o files?

This is a discussion on what to do with .o files? within the C++ Programming forums, part of the General Programming Boards category; So I gave ubuntu a shot, been hearing some cool stuff about linux and it's always good to learn new ...

  1. #1
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118

    what to do with .o files?

    So I gave ubuntu a shot, been hearing some cool stuff about linux and it's always good to learn new things so I thought why not. I've still got windows installed on my system as well.

    After having a look at some of the c++ IDEs available for linux I found one and made a simple hello world program. I built it, compiled it and executed it and it worked from within the IDE.

    Then I closed the IDE (geany, for those who are wondering) and located the program within my documents. I found it and opened it and I got a complaint that it didn't recognise the file type. It was a .o file.

    Basically I'm wondering a couple of things

    a) How can I open the program I made outside the IDE?

    b) How can I create files which other people can download and run from my site (like a .exe for example) or am I condemned to programming in windows if I want to do this?

    c) Is there a way for users using OS X or Windows to download and run .o files?

    Basically I like to distribute the programs I make. It's one of the primary reasons for doing it

    Thanks for your help

    Kind Regards

    Stonehambey

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    The .o file is not the program. There is another executable file somewhere that is being run. The .o file is the object file created when you compile a source file. Basically, each source file is compiled into its own .o file. Then all the .o files are linked by the linker into an executable. You need to find the executable.

    It might be named a.out. It could also be in a different folder. It probably won't have an exe file extension.

  3. #3
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    Thanks for the swift reply mate

    So would it be the same type of executable file that a windows user could run for example? Would I need to do anything to it before I uploaded the file for others to download?

    Can I run this executable file from within ubuntu?

    Sorry for the rather n00bish questions, if this has all been asked before just point me in the right direction

    Kind Regards

    Stonehambey

    EDIT: After a bit of digging I found this

    https://answers.launchpad.net/ubuntu/+question/16799

    So if this is the case, which file is the IDE running? (I know I haven't installed wine, although if it lets me run exe files then it looks like a good thing to install)
    Last edited by Stonehambey; 05-06-2008 at 11:04 AM.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    When you build something on one platform, that file will only run on that platform. So if you compile your code on Ubuntu, you can't run that executable file on Windows. You have to build it for Windows to run it on Windows.

    I don't think that link applies to you. That is for an executable built for Windows that you want to run on Ubuntu, not the other way around. Wine is a windows emulator that allows you to run programs meant for Windows on your Linux machine.

    As far as finding the executable file that the IDE is running, it depends on the IDE. Just search the project properties or settings and look for the output file. I'm not familiar with geany so I can't tell you exactly. You can also try running the files in your directory to find one that executes.

    If you want to allow others to download your executable to run on Linux, you don't have to do anything except find the right file (although you should build it in release mode if that option exists).

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    It seems what you've done is compile the code. Produced object files.
    But what you forgot is link the files. The last step which takes the object files and produces the actual executable.
    You should run the linker, if the IDE doesn't handle it for you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Elysia, I think you missed the part where Stonehambey said that the code executed from inside the IDE and worked. I'm sure it is linked, he or she just can't find the output file.

  7. #7
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    Quote Originally Posted by Daved View Post
    Elysia, I think you missed the part where Stonehambey said that the code executed from inside the IDE and worked. I'm sure it is linked, he or she just can't find the output file.
    Yeah, it was a simple interactive program (enter a number, program displays the entered number) which worked when I ran it, so it's definitely all compiled and linked. I just had trouble finding the output file (not on my machine at the moment, but will let you know how I get on)

    It's a bit of a shame I can't write and distribute all my programs on one OS, I guess maybe that's one thing Java has over C++, but I just love C++ :P

    Thanks for the help guys

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Quote Originally Posted by Daved View Post
    Elysia, I think you missed the part where Stonehambey said that the code executed from inside the IDE and worked. I'm sure it is linked, he or she just can't find the output file.
    Ah, I must have missed that one!
    OK, my bad.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You could just distribute the source, you know.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 06:55 AM
  2. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21