Menu

Creating object files

jgr
2004-04-03
2012-09-26
  • jgr

    jgr - 2004-04-03

    Hi everyone!!!

    I would like to know how to compile object files (*.o) instead of doing it all the way to the *.exe files. I do add -c to the compiler commands (in fact I add -Wall -pedantic -ansi -g -c) but I noticed that when it compiles it adds by itself a -o file_name.exe (defines the output file to be .exe) and when I add a -o file_name.o to override the other command the compiles says that the output file is defined twice. And no, I don't want to use a project because this is an academic program that I must do this way. I also tryed to compile through the command line defining path c:\Programas\Dev-Cpp\bin in order to be able to compiling in my working directory with c++ -Wall -pedantic -ansi -g -c file_name.cpp but when I do it the compiler is unable to find the standard library files from Dev-Cpp\include\c++.... I would appreciate a lot any kind of help.
    Thanks

     
    • Nobody/Anonymous

      It'll output directly to the .exe when there's only one cpp file to create: there's no need to create a .o in this case.

      One simple hack would be to add a cpp file that is blank to the project (or put some function that does nothing and is never called) to force it to compile both to .o's and the link them.

      JMan

       
    • Amanda Wee

      Amanda Wee - 2004-04-03

      hmm... I had the impression that with a project you would have the object files in the project's workspace directory.

      "And no, I don't want to use a project because this is an academic program that I must do this way."
      That you must do from command line?
      Maybe instead of using the MinGW port of GCC under Dev-C++, you should use it under the MSYS environment.
      You can read more at:
      http://www.mingw.org

       
    • Anonymous

      Anonymous - 2004-04-04

      Unfortunately Dev-C++ does not have a compile-only option. It would be useful.

      You could achieve what you need by creating a project with a dummy file containing a definition for main(), plus the file for which you need to create the object code. However you have said that you don't want to do that.

      To compile from the command line, you either need to set the Include and Library paths explicitly using the -L and -I options (this is what Dev-C++ does, compile a dummy project or source and check the compile log to see the options it uses), or you can set standard include and library paths via environment variables. http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Environment-Variables.html#Environment%20Variables. Specifically LIBRARY_PATH, and CPATH.

      How you set up environment variables depends on what version of Windows you are using.

      Clifford.

       
      • Anonymous

        Anonymous - 2004-04-07

        Nobody picked me up on that one. Dev-C++ does have a compile only option: Execute|Compile current file... (shift-ctrl-F9).

        However everything else I states still stands. Note that creating a project ensures that ecerytime you compile the file, it uses the correct options. Compiling a file or building without a project uses the global default options, if you change them for one file, you affect everything else that you subsequently build.

        Another method of building from the command line is to use the Dev-C++ generated makefile, with the required object file as the target, e.g.:

        make mycode.o

        Clifford.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.