LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2012, 02:02 PM   #1
DemiSheep
LQ Newbie
 
Registered: Dec 2010
Posts: 17

Rep: Reputation: 0
Question How can I get my program to compile on Unix?


I am working on a school project in C++ and am using our schools unix server to write it as instructed by the professor. I am using vim and g++ to compile.

This project is built off another project, Lab0 which I had no trouble getting to build after some help from the TA, but had to do some weird stuff to get it to build (#include LinkedSortedList.cpp file at the bottom of LinkedSortedList.h). Everyone in the class did this weird stuff with #include .cpp file.

First, here are the files and what #includes they have for Lab0 which is compiling fine:

(The post is not showing my tabs in my makefile but they're there!)

makefile:

main: *.cpp *.h

g++ -o LSL main.cpp

clean:

rm -f *.o LSL*



Lab0 (The one that builds), is like this:

Files:

main.cpp (NOT Templated):
#include "LinkedSortedList.h"
#include <iostream>
using namespace std;

SortedList.h (Templated):
Nothing

LinkedNode.h (Templated):
#include <iostream>
using namespace std;

LinkedSortedList.h (Templated):
#include "SortedList.h"
#include "LinkedNode.h"
#include <iostream>
using namespace std;

#include "LinkedSortedList.cpp" - At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.

LinkedSortedList.cpp (Templated):
Nothing

No problems building and running this project.


Below is lab1, the one I am having trouble with and Lab1 uses all the files from Lab0 just adds Employee.h and Employee.cpp.

Lab1 (The one that won't build) is like this:

Files:

lab1.cpp:
#include <iomanip>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include "Employee.h"
#include "LinkedSortedList.h"

SortedList.h (Templated):
Nothing

LinkedNode.h (Templated):
#include <iostream>
using namespace std;

LinkedSortedList.h (Templated):
#include "SortedList.h"
#include "LinkedNode.h"
#include "Employee.h"
#include <iostream>
using namespace std;

#include "LinkedSortedList.cpp" - At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.

LinkedSortedList.cpp (Templated):
Nothing

Employee.h (NOT templated):
#include <iostream>
#include <sstream>
using namespace std;

Employee.cpp (NOT templated):
#include <stdio.h>
#include <string.h>


(The post is not showing my tabs in my makefile but they're there!)

makefile:

main: *.cpp *.h

g++ -o LSL lab1.cpp

clean:

rm -f *.o LSL*




Errors I get:

Here are the errors I am getting. It seems like the Employee.cpp/Employee.h files are not being seen. Any ideas??

Code:
unixserver:Lab1> make
g++ -o LSL lab1.cpp
/tmp/ccamnaqx.o: In function `createRecord()':
lab1.cpp:(.text+0x3fb): undefined reference to `Employee::Employee()'
lab1.cpp:(.text+0x477): undefined reference to `Employee::setLastName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x4f2): undefined reference to `Employee::setFirstName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x589): undefined reference to `Employee::setId(int)'
lab1.cpp:(.text+0x5ce): undefined reference to `Employee::setSalary(int)'
lab1.cpp:(.text+0x60e): undefined reference to `Employee::setDepartment(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x67c): undefined reference to `Employee::setPhoneNumber(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x6ea): undefined reference to `Employee::setAddress(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x758): undefined reference to `Employee::setHireDate(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x7c6): undefined reference to `Employee::setEmailAddress(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status
make: *** [main] Error 1
Any help would be greatly appreciated!
 
Old 04-28-2012, 02:14 PM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Code:
g++ -o LSL lab1.cpp
You're only compiling the lab1.cpp. You shoud also add Employee.cpp:

Code:
g++ -o LSL lab1.cpp Employee.cpp
 
Old 04-28-2012, 05:03 PM   #3
DemiSheep
LQ Newbie
 
Registered: Dec 2010
Posts: 17

Original Poster
Rep: Reputation: 0
Thank you that worked!
 
Old 04-29-2012, 02:30 PM   #4
ejspeiro
Member
 
Registered: Feb 2011
Distribution: Ubuntu 14.04 LTS (Trusty Tahr)
Posts: 203

Rep: Reputation: 26
Cool

Hello DemiSheep:

You should use the PHP wrappers so that your code looks cool: [-PHP-] Your code [-/PHP-] without the '-'. That would provide color syntax and it would respect the spaces!

PHP Code:
#include <awesome.h> 
Hope you find this useful since your main concern was already solved.

Quote:
Everyone in the class did this weird stuff with #include .cpp file.
As a word of advice man, learn to really trust in your coding... when you ask your buddies for tips, not because they all have done something, it doesn't mean is 0k! Friends are definitely a good resource for help, but if sometimes you think they are wrong and you are not, then keep validating by other means, as for example these forums in where questions are always welcome!

\m/
 
Old 04-29-2012, 06:27 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by ejspeiro View Post
You should use the PHP wrappers so that your code looks cool: [-PHP-] Your code [-/PHP-] without the '-'. That would provide color syntax and it would respect the spaces!
PHP Code:
#include <awesome.h> 
Beg to differ, [code][/code] tags get the job done just fine, and don't use that awful orange colour.
 
1 members found this post helpful.
Old 04-29-2012, 08:07 PM   #6
ejspeiro
Member
 
Registered: Feb 2011
Distribution: Ubuntu 14.04 LTS (Trusty Tahr)
Posts: 203

Rep: Reputation: 26
ntubski xD I guess... for some reason I have always love green for preprocessing!

xD
 
Old 04-29-2012, 09:05 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by ntubski View Post
Beg to differ, [code][/code] tags get the job done just fine, and don't use that awful orange colour.
+1


I commonly encourage people posting with PHP tags not to, for varied reasons:
a) the colour coding sucks (more so for other languages than PHP)
b) the scroll-behaviour of the PHP box sucks.



Cheers,
Tink
 
Old 04-29-2012, 09:07 PM   #8
ejspeiro
Member
 
Registered: Feb 2011
Distribution: Ubuntu 14.04 LTS (Trusty Tahr)
Posts: 203

Rep: Reputation: 26
Nice! I will from now on!

\m/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Unix program gaurav151087 Linux - Networking 3 05-05-2011 03:02 AM
C program in unix environment savard Programming 5 01-12-2011 04:06 AM
Compile Unix App for Calculator worldgnat Programming 2 09-01-2007 10:54 AM
How to program under Linux/Unix platform Igor007 *BSD 1 08-19-2004 02:14 PM
How to program thread in Unix OS?? lamvd Programming 2 01-27-2003 06:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration