a few really simple questions

Joined
Aug 22, 2010
Messages
10
Reaction score
0
Points
1
Hi, all –

After a departure from software development of almost 20 years, I'm wading back in. (I'm going to be writing simulators and UIs for dedicated processors.) In addition to needing to learn C++, I need to refresh my skills with the development tools.

I have a few questions which I'm sure are going to seem incredibly lame:

1. I found a C++ version of hello world. When I try to compile it, I get a bunch of error messages:

Code:
Undefined symbols:
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
      _main in ccFTxGWv.o
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int)in ccFTxGWv.o
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
      std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccFTxGWv.o
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const", referenced from:
      std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccFTxGWv.o
      std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccFTxGWv.o
      std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccFTxGWv.o
  "___gxx_personality_v0", referenced from:
      std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccFTxGWv.o
      _main in ccFTxGWv.o
      ___tcf_0 in ccFTxGWv.o
      unsigned long const& std::min<unsigned long>(unsigned long const&, unsigned long const&)in ccFTxGWv.o
      __static_initialization_and_destruction_0(int, int)in ccFTxGWv.o
      global constructors keyed to mainin ccFTxGWv.o
      CIE in ccFTxGWv.o
  "std::ios_base::Init::~Init()", referenced from:
      ___tcf_0 in ccFTxGWv.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
      _main in ccFTxGWv.o
  "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> >&))", referenced from:
      _main in ccFTxGWv.o
  "std::cout", referenced from:
      _main in ccFTxGWv.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

The same command works fine on a C file, so I assume I'm misusing the command. Can someone help?

2. How does one link? I simply don't remember.

3. I'm trying to decide on a development environment. Does anyone have an opinion on Eclipse? I downloaded it and started playing with it, but at first glance, it looks like more than I need for a single-person project with what I expect to be relatively modest development requirements. I'm going to look at XCode, too, but I'm considering just working within the terminal window.

Thanks for helping me scrape some of the rust off.
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
Posting the source may help.

1. Check this thread regarding problem 1. Search for namespace in that thread.

2. man ld
found via: man -k link

3. Can't really help except to say consider your end result; Is this OS X only or will you need to deploy on multiple platforms. Xcode will handle everything from low level system stuff up to complicated GUI stuff, but is directed OS X.
 
OP
M
Joined
Aug 22, 2010
Messages
10
Reaction score
0
Points
1
1. hmm...my .cpp file does have the "using namespace std;" line in it. Do I need to do anything on the command line other than just "gcc hello.cpp"?

2. OK, thanks...I'll look at the man pages (argh) a little later, once I get my compile errors/warnings resolved.

3. Oh, that's very good information. I won't be targeting the Mac platform at all, so I guess XCode is out of the question.

Thanks for the help.
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
I don't know C++ so don't have a definitive answer. Playing around I found that I had to use "g++ hello.cpp -o hello" to actually compile the code. You then run it via "./hello" if within that directory.

I thought gcc was capable of cross platform compiling. If so, then XCode might be usable.
 
OP
M
Joined
Aug 22, 2010
Messages
10
Reaction score
0
Points
1
Excellent! That "g++" command worked fine. It also produced an executable (which I wasn't expecting; back when I was coding, after we compiled, we had to run a linker to produce an executable). So, I gather that the gnu compiler is an "all in one" package?

How do you tell the shell to look in your current directory for an executable? I seem to remember something about a .login file in my home directory, but I can't remember the command.

Thanks.
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
I'm sure you'll need to learn about the linker. Don't assume that a single file with a main() function it acts the same as many different files compiled to be used in a larger app.

Look into the PATH shell variable for the shell you are running and which .login or .profile, or maybe .chsrc file name to use to set that up when you start the terminal. The default shell for OS X is now Bash.

The following Google search came up with some interesting links regarding the shell login stuff; "OS X" bash shell login script
 

pigoo3

Well-known member
Staff member
Admin
Joined
May 20, 2008
Messages
44,208
Reaction score
1,411
Points
113
Location
U.S.
Your Mac's Specs
2017 15" MBP, 16gig ram, 1TB SSD, OS 10.15
I would suggest that you've chosen a really bad title...your questions are NOT "a few really simple questions"!;)

If they were "really simple"...you would probably be able to answer them yourself...and if they were "really simple" I and many others would probably be able to answer them. I have absolutely no experience programming in C++...so these are DEFINITELY not "simple questions"!;)

To me..."a few really simple questions would be":

- How do I turn on my Macintosh?
- How much does 1+1+1=?
- How many fingers does the average human have?
- What's heavier...10 pounds of feathers or 10 pounds of rocks?

Ha ha...just having a little fun? I think that a better title would be..."A few really hard questions!"...IMHO.;)

- Nixk
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top