Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

C++ links

No description
by

TsungYi Li

on 22 January 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of C++ links

C++ Links
Basic
C Run-Time Library (CRT)
Other Issues
Link Errors
LNK 2001
Declaration and Definition
One Definition Rule (ODR)
Multithreaded, Static Link
LIBCMT.LIB
LIBCMTD.LIB
CRT Mismatch
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in Gt2ServerPanel_2003.lib(ServerMainFrame.obj)
Name Mangling
#ifdef __cplusplus
extern "C" {
#endif
/* ... */
#ifdef __cplusplus
}
#endif
Linkage
Internal Linkage
Calling Convention
SDK Team
unresolved external symbol "symbol"
LNK 2005
symbol already defined in object
LNK 2019
unresolved external symbol 'symbol' referenced in function 'function'
(a.cpp)
extern int x;

void Foo()
{
++x;
}
(a.cpp)
void Qoo();

void Foo()
{
Qoo();
}
(c.h)
void Foo()
{
}
(a.cpp)
#include "c.h"
(b.cpp)
#include "c.h"
Declaration
Definition
extern int x;
extern const int y;
int f( int );
struct s;
typedef int Int;
extern X anotherX;
using N::d;
int a;
extern const int c = 1;
int f( int x ) { return x+a; }
struct S { int a; int b };
struct X { int x;
static int y;
X() : x( 0 ), y( 0 ) {} };
int X::y = 1;
enum { up, down };
namespace N { int x; }
namespace N1 = N;
X anX;
In any
translation unit
, a template, type, function, or object can have no more than one definition. Some of these can have any number of declarations. A definition provides an instance.
In the entire program, an object or non-inline function cannot have more than one definition; if an object or function is used, it must have exactly one definition. You can declare an object or function that is never used, in which case you don't have to provide a definition. In no event can there be more than one definition.
Some things, like types, templates, and extern inline functions, can be defined in more than one translation unit. For a given entity, each definition must be the same. Non-extern objects and functions in different translation units are different entities, even if their names and types are the same.
1
2
3
Translation Unit
The ultimate input to a C compiler from which an object file is generated. A translation unit roughly consists of a source file after it has been processed by the C preprocessor, meaning that header files listed in #include directives are literally included, sections of code within #ifdef are included or not, and macros have been expanded.
Multithreaded, Dynamic Link
MSVCRT.LIB
MSVCRTD.LIB
Visual Studio .NET 2003
msvcr71.dll
msvcr71d.dll
Visual Studio 2010
msvcr100.dll
msvcr100d.dll
Visual Studio 2008
msvcr90.dll
msvcr90d.dll
Single-threaded, Static Link
LIBC.LIB
LIBCD.LIB
void h( int );
?h@@YAXH@Z
void h( int, char );
?h@@YAXHD@Z
External Linkage
(Implicitly Static)
const int ci = 1;
(Explicitly Static)
static const int sci = 0;
static int si = 5;
(Implicitly Extern)
int i = 4;
(Explicitly Extern)
extern const int eci = 2;
extern int ei = 3;
(c.cpp)
#include "a.h"
#include "b.h"

int main()
{
ShowA();
ShowB();
}
(a.h)
void ShowA();
(b.h)
void ShowB();
(c.h)
static int s = 0;
(a.cpp)
#include "a.h"
#include "c.h"

void ShowA()
{
std::cout << &s << std::endl;
}
(b.cpp)
#include "b.h"
#include "c.h"

void ShowD()
{
std::cout << &s << std::endl;
}
00765DB0
00765DBC
(c.cpp)
#include "a.h"
#include "b.h"

int s = 0;

int main()
{
ShowA();
ShowB();
}
(a.h)
void ShowA();
(b.h)
void ShowB();
(c.h)
extern int s;
(a.cpp)
#include "a.h"
#include "c.h"

void ShowA()
{
std::cout << &s << std::endl;
}
(b.cpp)
#include "b.h"
#include "c.h"

void ShowD()
{
std::cout << &s << std::endl;
}
00765DA0
00765DA0
__stdcall
__thiscall
__cdecl
Default calling convention for C and C++
Pushes parameters on the stack, in reverse order (right to left)
Caller cleanup stack
Used to call Win32 API functions
Pushes parameters on the stack, in reverse order (right to left)
Callee cleanup stack
Used on member functions
Pushed on stack; this pointer stored in ECX
Callee cleanup stack
Q and A
(Project A)

Multithreaded, dynamic link (debug) (/MDd)
(Project B)

Multithreaded, static link (debug) (/MTd)
linker errors as: MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __mktime64 already defined in LIBCMTD.lib(mktime64.obj)
(Project A)

using MFC as static library
(Project B)

using MFC as shared DLL
nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
(b.cpp)
int x = 0;
(c.h)
inline void Foo()
{
}
(c.h)
void Foo();
(c.cpp)
void Foo()
{
}
(b.cpp)
void Qoo()
{
}
Link.obj : error LNK2005: "void __cdecl Lnk2005(void)" (?Lnk2005@@YAXXZ) symbol already defined in object LinkErrors.obj
LinkErrors.obj : error LNK2019: unresolved external symbol "int __cdecl Lnk2019(void)" (?Lnk2019@@YAHXZ), referenced in function _main
LinkErrors.obj : error LNK2001: unresolved external symbol "int lnk2001" (?lnk2001@@3HA)
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in Gt2ServerPanel_2003.lib(ServerMainFrame.obj)
Full transcript