Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Can't compile code in linux

  1. #1
    Join Date
    Oct 2006
    Beans
    324

    Can't compile code in linux

    i have a problem compiling a very simple c++ in linux.

    Basically i have written ,compiled and run the program in Microsoft visual studio 2008 and it runs flawlessly but the same code on linux doesn't compile.

    I tried with geany , codeblocks and the command line but i get the same error every time

    the program is consisted by 3 files the main.cpp math.h and math.cpp
    the main.cpp is the file tha includes the main function

    i get this when i try to compile main.cpp
    main.cpp.text+0xa): undefined reference to `menu()'
    main.cpp.text+0x83): undefined reference to `square_of_number(double)'
    main.cpp.text+0xfe): undefined reference to `sum_of_numbers(double, double)'
    main.cpp.text+0x179): undefined reference to `product_of_numbers(double, double)'

    and this when i try to compile math.cpp
    start.S:115: undefined reference to `main'

  2. #2
    Join Date
    Jun 2007
    Location
    Paraparaumu, New Zealand
    Beans
    Hidden!

    Re: Can't compile code in linux

    Are you able to show us some code?
    If you do, put [code] at the start and [/code] at the end
    Forum DOs and DON'Ts
    Please use CODE tags
    Including your email address in a post is not recommended
    My Blog

  3. #3
    Join Date
    Mar 2010
    Beans
    6

    Re: Can't compile code in linux

    Code:
    g++ main.cpp math.h math.cpp -o main
    -- or simply add an include statement in main.cpp.

  4. #4
    Join Date
    Oct 2006
    Beans
    324

    Re: Can't compile code in linux

    Quote Originally Posted by Sim & Co. View Post
    Code:
    g++ main.cpp math.h math.cpp -o main
    -- or simply add an include statement in main.cpp.
    if i put this in terminal it doesn't show the error messages,what does this mean? How can i run the program to see if it works?

    Sorry if i make a lot of questions but i mainly program on visual studio but i also want to learn on linux

    By the way thanks both for replying

  5. #5
    Join Date
    Mar 2010
    Beans
    6

    Re: Can't compile code in linux

    No error messages - possible ( most of the bugs doesn't show off just like that ) success.

    Code:
    ./main
    ** Execute it from the directory you were in when you compiled your application.

  6. #6
    Join Date
    Oct 2006
    Beans
    324

    Re: Can't compile code in linux

    Quote Originally Posted by Sim & Co. View Post
    No error messages - possible ( most of the bugs doesn't show off just like that ) success.

    Code:
    ./main
    ** Execute it from the directory you were in when you compiled your application.
    It worked.Thanks a lot

    But do you know a way to do this in geany?

  7. #7
    Join Date
    Mar 2010
    Beans
    6

    Re: Can't compile code in linux

    Quote Originally Posted by fasoulas View Post
    It worked.Thanks a lot

    But do you know a way to do this in geany?
    Wikipedia know how to

  8. #8
    Join Date
    Oct 2006
    Beans
    324

    Re: Can't compile code in linux

    Quote Originally Posted by Sim & Co. View Post
    Wikipedia know how to
    OK i will search and find.

    thanks again

  9. #9
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: Can't compile code in linux

    A header file won't solve the linking problem
    undefined reference is an error in the linking stage, not the compile stage.

    What the compiler did in Sim's line is following:
    gcc -c math.cpp -o math.o //compile math.cpp to object file
    gcc -c main.cpp -o main.o //compile main.cpp to object file
    gcc main.o math.o -o math // link main.o and math.o to math executable


    so far I know geany has no (yet) got a good way to do this without makefiles.
    A makefile is a file containing all the build rules executed with the command make
    http://www.gnu.org/software/make/manual/make.html

  10. #10
    Join Date
    Mar 2010
    Beans
    6

    Re: Can't compile code in linux

    Quote Originally Posted by fasoulas View Post
    OK i will search and find.

    thanks again
    What are you going to search for ? The link points to a specific section and all you need to do is read and understand it

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •