C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-12-2007, 03:38 PM   #1
Registered User
 
Join Date: Aug 2006
Posts: 159
first program in *nix

Edit: Ok, so I should have been using g++ instead of gcc for the .cpp file. That's settled. New question though, how do I link files that I have included? Say if I write a program and I want to include curses.h, how do I compile that?

Everything below this is the original question.



Hi all. Up until this point I've always written and compiled my programs in Windows. I got a Macbook Pro a couple of months ago, and figure it's time to start programming in Unix. I'm not very advanced in terminal, so it took me a bit of time to try to even get to the proper directory. I finally got the commands correct to compile but I got errors on everything, including a hello world program!


Every time I try to compile something I get this:
Code:
/usr/bin/ld: Undefined symbols:
And a bunch of stuff depending on what I'm trying to compile

for
Code:
#include <iostream>
using namespace std;

int main( int argc, char *argv[] )
{
    cout << "Hello World" << endl;
    return 0;
}
I get this in the terminal:

Code:
current directory$ gcc -o helloworld helloworld.cpp
/usr/bin/ld: Undefined symbols:
std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
std::ios_base::Init::Init()
std::ios_base::Init::~Init()
std::cout
std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
___gxx_personality_v0
collect2: ld returned 1 exit status
I have no idea what most of this means. Is there a reason why such a simple program won't compile? I know it's probably something stupidly simple, but as I've never worked in this environment before, it's totally beyond me.

If anybody can offer some advice, or show me a good starters guide to writing/compiling c/c++ in *nix, that be great.

Thanks so much.

Ed

Last edited by System_159; 09-12-2007 at 04:09 PM. Reason: answered previous question, new question added
System_159 is offline   Reply With Quote
Old 09-12-2007, 04:17 PM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,680
g++ prog.cpp -lcurses
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 09-12-2007, 06:23 PM   #3
Registered User
 
Join Date: Aug 2006
Posts: 159
Quote:
Originally Posted by Salem View Post
g++ prog.cpp -lcurses
Thanks. That solved the curses.h linker error. What do I for custom header files? I've got three header files that I'm including:

Code:
#include "includes/mnemonics.h" 
#include "gui/draw_menu.h"
#include "gui/menus.h"
Thanks again for the help Salem. I'm currently fiddling around with the system while I wait to find out how to link those headers.
System_159 is offline   Reply With Quote
Old 09-12-2007, 06:50 PM   #4
Protocol Test Engineer
 
ssharish2005's Avatar
 
Join Date: Sep 2005
Location: fseek(UK)
Posts: 1,324
Code:
g++ -I../includes../gui -o helloworld helloworld.cpp -lcurses
ssharish

Last edited by ssharish2005; 09-12-2007 at 06:55 PM.
ssharish2005 is offline   Reply With Quote
Old 09-12-2007, 10:12 PM   #5
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,295
Do nothing with the custom header files, leave them as they are, don't attempt to compile them seperatly (ie just leave the compiler switches as they are).

You may also want to turn up the warning level and stuff, do a man gcc

You don't need to specify -I, because you explicitly define the directory where the headers are.
Quote:
Originally Posted by man gcc
-I dir
Add the directory dir to the list of directories to be
searched for header files. Directories named by -I are
searched before the standard system include directories.
If the directory dir is a standard system include
directory, the option is ignored to ensure that the
default search order for system directories and the
special treatment of system headers are not defeated .
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim

Last edited by zacs7; 09-12-2007 at 10:17 PM.
zacs7 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with program that's calling a function and has a loop tigerfansince84 C++ Programming 9 11-12-2008 01:38 PM
Need help with a program, theres something in it for you engstudent363 C Programming 1 02-29-2008 01:41 PM
This is a simple program.. Help me please I think it has an error.. lesrhac03 C Programming 4 02-21-2008 10:39 AM
My program, anyhelp @licomb C Programming 14 08-14-2001 10:04 PM


All times are GMT -6. The time now is 08:03 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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