Jump to content

Linking

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
pokevitek

pokevitek

    Newbie

  • Members
  • PipPip
  • 21 posts
Hi, as I go further into C++, there is often mentioned linking. But, I don´t know what it means. When I try to google it, all I get is "I have this linking error xxx" and so. Please, what is linking?

#2
Sysop_fb

Sysop_fb

    Programmer

  • Members
  • PipPipPipPip
  • 160 posts
Linking is a process done by a linker such as ld that links together 1 or more object files and produces an executable file.
Linker (computing) - Wikipedia, the free encyclopedia
Generally by either using an IDE or a compiler directly through command line (ex. gcc -o test test.c) you might not of ever had to worry about linking before because a compiler such as gcc will handle compiling the c code into asm passing it on to an assembler which produces an object file and then passes the object file onto the linker for production of a executable. Unless you tell it not to..

#3
pokevitek

pokevitek

    Newbie

  • Members
  • PipPip
  • 21 posts
Thanks,but I explained my problem somehow bad... Becouse, I know this, but I don´t understand. I mean, according to wiki, object files are files with machine code, and they are joined together by linker. But I don´t understand why we need to have these object files separatelly. I am c++ beginner, I am stuck with my console game project to learn more about it. So I have only one cpp source file, and I compile it into .exe file using Visual Studio Express, or before dev c++.

#4
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
It doesn't make much sense if you only have one source file. It makes a whole lot more sense when you have dozens, hundreds. Then if you want change one line of code in just one file, you don't have so sit through as the compiler rebuilds a couple hundred files.

In general, however, you'll want to have code grouped together in multiple source files.

#5
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
sometime you don't need to have them separately but you don't have a choice - for example if you have to use a library written by someone else and they do not supply you the source code, only the Interface and the object file implementing the library.
So in addition to the stated above, using multiple source files also enables other people to use your code, but know nothing about the way its implemented.