473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Compiling multiple source files.......

Ok, stupid question....

I used to write programs all into one text files and compile them.
Works, fine.
Then I discovered XCode (or IDEs in general) which appear to be really
increasing my productivity, so I use XCode with the settings for a
command line C++ tool. Works fine, too. Then I split up my source code
into many files. After figuring out the #ifndef stuff, that works great,
even better.

No on my machine everything works fine so I want to run the programs on
the linux cluster. Figured out that this requires recompiling, ok. So I
copied all the source files and run g++ - error. Same thing on my
machine - error. Looks like this:

Undefined symbols:
"AdaptiveNW::progressSystem()", referenced from:
_main in ccTK2FsI.o
"AdaptiveNW::outCurrDegDist()", referenced from:
_main in ccTK2FsI.o
"AdaptiveNW::AdaptiveNW(int, int, int)", referenced from:
_main in ccTK2FsI.o
Since these are .o files, i figured that this is related to the linking
of the output files, which may or may not be something that make does in
Linux. I tried to read on make and its usage, but it seems way way too
complicated for something as simple as what I do here (I'd rather just
concatenate the source files into one....).

Is there any simple way to solve this? A hint on where to get _concise_
introductions on how to use make (i.e. how to use make to do
helloworld.cpp) would be more than enough....

Thanks, Oliver
Aug 18 '08 #1
6 3501
Sam
Oliver Graeser writes:
Is there any simple way to solve this? A hint on where to get _concise_
introductions on how to use make (i.e. how to use make to do
helloworld.cpp) would be more than enough....
The following one-line makefile should be sufficient to compile and link
a C++ program consisting of one module, helloworld.cpp:

helloworld: helloworld.o

When the C++ program is composed of multiple modules, hello.cpp and
world.cpp:

helloworld: hello.o world.o

Linux's make is GNU make, which is far more advanced then the traditional
Unix make, and comes built-in with a rich set of default rules that enables
you to build stuff with just a minimum of a specification. The default rules
will be sufficient to do basic, simple, builds.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkio5xsACgkQx9p3GYHlUOJ5awCfYZd44M6F0/scKBlfBYIiDZDd
MuwAnjSifCoaJy/a6i+kuISggLyl4xPs
=JExA
-----END PGP SIGNATURE-----

Aug 18 '08 #2
Sam wrote:
Oliver Graeser writes:
>Is there any simple way to solve this? A hint on where to get
_concise_ introductions on how to use make (i.e. how to use make to do
helloworld.cpp) would be more than enough....

The following one-line makefile should be sufficient to compile and link
a C++ program consisting of one module, helloworld.cpp:

helloworld: helloworld.o

When the C++ program is composed of multiple modules, hello.cpp and
world.cpp:

helloworld: hello.o world.o

Linux's make is GNU make, which is far more advanced then the
traditional Unix make, and comes built-in with a rich set of default
rules that enables you to build stuff with just a minimum of a
specification. The default rules will be sufficient to do basic, simple,
builds.
<OT>As do most, if not all versions of make. Nothing unique about GNU
make there.</OT>

--
Ian Collins.
Aug 18 '08 #3
Ian Collins wrote:
Sam wrote:
>Oliver Graeser writes:
>>Is there any simple way to solve this? A hint on where to get
_concise_ introductions on how to use make (i.e. how to use make to do
helloworld.cpp) would be more than enough....
The following one-line makefile should be sufficient to compile and link
a C++ program consisting of one module, helloworld.cpp:

helloworld: helloworld.o

When the C++ program is composed of multiple modules, hello.cpp and
world.cpp:

helloworld: hello.o world.o

Linux's make is GNU make, which is far more advanced then the
traditional Unix make, and comes built-in with a rich set of default
rules that enables you to build stuff with just a minimum of a
specification. The default rules will be sufficient to do basic, simple,
builds.
<OT>As do most, if not all versions of make. Nothing unique about GNU
make there.</OT>
Thanks! So I guess I have to compile all my .cpps to .os. However if I
try now to compile the source files separately, it seems that the
compiler is unable to find the header files (which are in the same
directory??):

g++ AdaptiveNW.cpp AdaptiveNW.o

g++ AdaptiveNW.cpp -o Adaptive.o
In file included from SISNetworkNode.h:11,
from AdaptiveNW.cpp:12:
GNN.h:13:24: error: calling fdopen: Bad file descriptor
In file included from SISNetworkNode.h:12,
from AdaptiveNW.cpp:12:
All files are in the same directory and semantically o.k., they compile
in xcode. Google hinted towards some precompiled headers (.gch) which I
ought to delete, but I didn't find these anywhere??
Aug 18 '08 #4
Oliver Graeser wrote:
Thanks! So I guess I have to compile all my .cpps to .os. However if I
try now to compile the source files separately, it seems that the
compiler is unable to find the header files (which are in the same
directory??):

g++ AdaptiveNW.cpp AdaptiveNW.o

g++ AdaptiveNW.cpp -o Adaptive.o
In file included from SISNetworkNode.h:11,
from AdaptiveNW.cpp:12:
GNN.h:13:24: error: calling fdopen: Bad file descriptor
In file included from SISNetworkNode.h:12,
from AdaptiveNW.cpp:12:
All files are in the same directory and semantically o.k., they compile
in xcode. Google hinted towards some precompiled headers (.gch) which I
ought to delete, but I didn't find these anywhere??
That look like a compiler issue, if the common -I compiler flag does not
work for you, try a gcc hemp forum.

--
Ian Collins.
Aug 18 '08 #5
Sam wrote:
The following one-line makefile should be sufficient to compile and link
a C++ program consisting of one module, helloworld.cpp:

helloworld: helloworld.o
If XCode works anything like gcc, then you can auto-generate those
lines. With gcc it happens like this:

gcc -MM *.cc

(Or whatever the extension of your source files is.)

If XCode does not support the -MM option, then it might be named in
some other way.

In fact, you can make the Makefile itself auto-generate those lines
and then include the generated file, like this:

# List source files (not headers!) and binary name:
SOURCES=$(wildcard *.cc)
BINARY=programname

# Set up compiler and compiler options:
CXX=g++
CXXFLAGS=-Wall -W -ansi -O3
LDLIBS=

# If you are compiling a C program (instead of C++), comment out this line:
LINK.o=$(LINK.cpp)
# --- No need to modify anything below this line ---
$(BINARY): $(SOURCES:.cc=.o)

..dep:
g++ -MM $(SOURCES) .dep

-include .dep

(Note that if the dependencies change because of added or removed
#include lines in the source files, you'll have to remove the .dep file
so that it will be rebuilt.)
Aug 18 '08 #6
Juha Nieminen <no****@thanks.invalidwrites:
If XCode works anything like gcc
Xcode is just Apple's IDE. The compiler under the hood *is* GCC.

sherm--

--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
Aug 18 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
1
by: Mike Hutton | last post by:
I need some help. I am trying to set up our development environment so as to make life easy for my fellow developers (none of whom have used ASP.NET or VS.NET before). We are developing our...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
6
by: Gaijinco | last post by:
I'm having a weird error compiling a multiple file project: I have three files: tortuga.h where I have declared 5 global variables and prototypes for some functions. tortuga.cpp where I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.