Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newbie question regarding different files

87 views
Skip to first unread message

ag...@drrob1.com

unread,
Oct 22, 2014, 8:30:15 AM10/22/14
to
I am trying to learn c++, after many years of hobby programming w/
modula-2, and recent ada programming.

I am mostly finished w/ a free edx.org course on c++. I have found
this worthwhile, but my question is this: how can I write a program
with dividing my code into separate files.

Modula-2 and ada both easily do separate compilation and linking. But
I don't know how to do this after taking an online course in c++.

Does this have something to do with make?

Thanks,
Rob


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Barry Schwarz

unread,
Oct 23, 2014, 6:00:16 AM10/23/14
to
On Wed, 22 Oct 2014 07:29:05 CST, ag...@drrob1.com wrote:

>I am trying to learn c++, after many years of hobby programming w/
>modula-2, and recent ada programming.
>
>I am mostly finished w/ a free edx.org course on c++. I have found
>this worthwhile, but my question is this: how can I write a program
>with dividing my code into separate files.
>
>Modula-2 and ada both easily do separate compilation and linking. But
>I don't know how to do this after taking an online course in c++.
>
>Does this have something to do with make?

This has more to do with the tools (compiler, linker, etc) that you
use to write, compile, and link the program than with the C++
language. Microsoft Visual Studio provides one method, gcc another,
etc. You can get detailed information for your system in a newsgroup
where it is topical.

--
Remove del for email

James K. Lowden

unread,
Oct 23, 2014, 6:10:18 AM10/23/14
to
On Wed, 22 Oct 2014 07:29:05 CST
ag...@drrob1.com wrote:

> I am mostly finished w/ a free edx.org course on c++. I have found
> this worthwhile, but my question is this: how can I write a program
> with dividing my code into separate files.

There is a difference between a language and a compiler. Your C++
class taught you how to express algorithms in the C++ language. Your
compiler is a tool and, like any tool, the best place to learn how to
use it is from its documentation. Not to say that's easy!

In the old days there were two tools, compiler and linker. The
compiler converted source code to object code, and the linker knitted
the object code modules and libraries together to form an executable.
Nowadays many tools combine these two functions into one. gcc is an
example.

The gcc manpage indicates the final argument as "infile...", meaning it
will process more than one input file at a time. These input files may
be any combination of C++ source code, object (.o), and libraries.
Absent options to the contrary, gcc will produce (if it can) an
executable file. The gcc option "-c" limits the invocation to
compilation, producing a ".o" object file.

Once a project has more than a few files, it's usually quicker to
compile each source file separately to object form, and link them as a
final step, because many changes require re-compilation of only one
source file.

Note of caution: GNU makes a linker, too, known as "ld". Last I
checked, you can't reliably use ld to link C++ object modules into an
executable or shared object. C++ imposes quite a bit of work on the
linker in the form of logic that executes before main() is run. That
was one motivation behind combining compiler and linker functionality
into one tool.

> Does this have something to do with make?

Since about 1975, yes. :-)

make is a tool much maligned but exceedingly useful, likely the only
declarative rule processor in your toolbox.

The problem make tackles is dependency tracking. After you edit and
save your source code, which object files (plural, it might have been a
header file you changed), libraries and executables are affected?
What, as we say, has to be rebuilt? make lets you define that
dependency graph logically, as a set of rules, and applies them based
on the files' timestamps.

Articles worthy of your time:

The Art of Unix Programming:
http://www.catb.org/esr/writings/taoup/html/ch15s04.html
(The whole TAOUP is worth reading.)

PMake ? A Tutorial
http://docs.freebsd.org/44doc/psd/12.make/paper.pdf

The pmake tutorial is ancient and describes a version of make you're
unlikely ever to use. Why point it out? Because it was written when
make was young, and assumes you've never seen such a tool before. If
you ignore some of the specifics, you'll get a nice introduction to the
basic ideas. That background will make your definitive resource, "info
make" (assuming you're using GNU make), easier to understand.

HTH.

--jkl

Truth

unread,
Oct 24, 2014, 9:31:13 AM10/24/14
to
On 10/23/2014 4:00 AM, James K. Lowden wrote:
> On Wed, 22 Oct 2014 07:29:05 CST
> ag...@drrob1.com wrote:
>
>> I am mostly finished w/ a free edx.org course on c++. I have found
>> this worthwhile, but my question is this: how can I write a program
>> with dividing my code into separate files.
[...]
>> Does this have something to do with make?
>
> Since about 1975, yes. :-)
>
> make is a tool much maligned but exceedingly useful, likely the only
> declarative rule processor in your toolbox.
[...]
> PMake ? A Tutorial
> http://docs.freebsd.org/44doc/psd/12.make/paper.pdf
>
> The pmake tutorial is ancient and describes a version of make you're
> unlikely ever to use. Why point it out? Because it was written when
> make was young, and assumes you've never seen such a tool before. If
> you ignore some of the specifics, you'll get a nice introduction to the
> basic ideas. That background will make your definitive resource, "info
> make" (assuming you're using GNU make), easier to understand.
>
> HTH.
>
> --jkl

Snipped well written, informative post for brevity. :-)

Once you get the basics down, one could also look into CMake. It's a
tool to help manage, (and more), make files.
http://www.cmake.org/

Nice synopsis.
http://www.cmake.org/Wiki/CMake

HTH as well. :)


ag...@drrob1.com

unread,
Oct 25, 2014, 8:34:07 AM10/25/14
to
thanks. That is very clear and helpful.

Rosario193

unread,
Oct 25, 2014, 8:40:31 AM10/25/14
to

On Wed, 22 Oct 2014 07:29:05 CST, ag...@drrob1.com wrote:

>I am trying to learn c++, after many years of hobby programming w/
>modula-2, and recent ada programming.
>
>I am mostly finished w/ a free edx.org course on c++. I have found
>this worthwhile, but my question is this: how can I write a program
>with dividing my code into separate files.
>
>Modula-2 and ada both easily do separate compilation and linking. But
>I don't know how to do this after taking an online course in c++.
>
>Does this have something to do with make?
>
>Thanks,
>Rob

there was someone that said that is not good break code in many files
if not dll...

Jorgen Grahn

unread,
Oct 26, 2014, 3:56:23 AM10/26/14
to
On Thu, 2014-10-23, James K. Lowden wrote:
> On Wed, 22 Oct 2014 07:29:05 CST
> ag...@drrob1.com wrote:
...

>> Does this have something to do with make?
>
> Since about 1975, yes. :-)
>
> make is a tool much maligned but exceedingly useful, likely the only
> declarative rule processor in your toolbox.
>
> The problem make tackles is dependency tracking. After you edit and
> save your source code, which object files (plural, it might have been a
> header file you changed), libraries and executables are affected?
> What, as we say, has to be rebuilt? make lets you define that
> dependency graph logically, as a set of rules, and applies them based
> on the files' timestamps.
>
> Articles worthy of your time:
>
> The Art of Unix Programming:
> http://www.catb.org/esr/writings/taoup/html/ch15s04.html
> (The whole TAOUP is worth reading.)
>
> PMake ? A Tutorial
> http://docs.freebsd.org/44doc/psd/12.make/paper.pdf

Also this one by the late Peter Miller:

Recursive Make Considered Harmful
http://aegis.sourceforge.net/auug97.pdf

> The pmake tutorial is ancient and describes a version of make you're
> unlikely ever to use. Why point it out? Because it was written when
> make was young, and assumes you've never seen such a tool before. If
> you ignore some of the specifics, you'll get a nice introduction to the
> basic ideas. That background will make your definitive resource, "info
> make" (assuming you're using GNU make), easier to understand.

Now I get the urge to write a paper called "The useful subset of Make"
... IME a well-written Makefile is easy to understand, read and use,
but people often seem to get trapped in the exotic constructs which
are really only there for backwards compatibility or rarely
encountered situations.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Francis Glassborow

unread,
Oct 26, 2014, 8:30:15 AM10/26/14
to

On 10/25/2014 2:34 PM, Rosario193 wrote:
>
> On Wed, 22 Oct 2014 07:29:05 CST, ag...@drrob1.com wrote:
>
>> I am trying to learn c++, after many years of hobby programming w/
>> modula-2, and recent ada programming.
>>
>> I am mostly finished w/ a free edx.org course on c++. I have found
>> this worthwhile, but my question is this: how can I write a program
>> with dividing my code into separate files.
>>
>> Modula-2 and ada both easily do separate compilation and linking. But
>> I don't know how to do this after taking an online course in c++.
>>
>> Does this have something to do with make?
>>
>> Thanks,
>> Rob
>
> there was someone that said that is not good break code in many files
> if not dll...
>
>


Well if they were talking abiut C++ they do not know very much about it. Breaking code into separate files is normal. Indeed whether you realise it or not all C++ executables rely on multiple files of code (because that is how libraries are provided)

Indeed it is usually consider good design to isolate classes into their own files (though sometimes where classes are inter-dependant it makes some sense to place them in the same file.

Francis

Jorgen Grahn

unread,
Oct 26, 2014, 12:28:04 PM10/26/14
to
On Sun, 2014-10-26, Francis Glassborow wrote:
>
> On 10/25/2014 2:34 PM, Rosario193 wrote:
...
>> there was someone that said that is not good break code in many files
>> if not dll...

> Well if they were talking abiut C++ they do not know very much about
> it. Breaking code into separate files is normal. Indeed whether you
> realise it or not all C++ executables rely on multiple files of code
> (because that is how libraries are provided)

> Indeed it is usually consider good design to isolate classes into
> their own files (though sometimes where classes are inter-dependant it
> makes some sense to place them in the same file.

(And sometimes it makes sense to split the implementation of a class
across several source files.)

Rosario193

unread,
Oct 26, 2014, 4:38:00 PM10/26/14
to
On Sun, 26 Oct 2014 07:27:46 CST, Francis Glassborow wrote:
>On 10/25/2014 2:34 PM, Rosario193 wrote:
>>
>> On Wed, 22 Oct 2014 07:29:05 CST, ag...@drrob1.com wrote:
>>
>>> I am trying to learn c++, after many years of hobby programming w/
>>> modula-2, and recent ada programming.
>>>
>>> I am mostly finished w/ a free edx.org course on c++. I have found
>>> this worthwhile, but my question is this: how can I write a program
>>> with dividing my code into separate files.
>>>
>>> Modula-2 and ada both easily do separate compilation and linking. But
>>> I don't know how to do this after taking an online course in c++.
>>>
>>> Does this have something to do with make?
>>>
>>> Thanks,
>>> Rob
>>
>> there was someone that said that is not good break code in many files
>> if not dll...
>>
>Well if they were talking abiut C++ they do not know very much about it.
>Breaking code into separate files is normal. Indeed whether
>you realise it or not all C++ executables rely on multiple
>files of code (because that is how libraries are provided)

i use monofile for dll... one dll for language etc...

one for cpp one for assembly
but possibly i put not too much code there...
0 new messages