CºÍC£«£«»ìºÏ±à³ÌÏà¹ØÎÊÌâ½â¾ö·½·¨
Ò» £º½â¾öC»òC++ÖеÄmultiple definition ofÎÊÌâ
server.cpp
clientp2p.cpp
#include "exception.h"
#include "clientp2p.h"
clientp2p.h
ÖÐдÓÐËùÓеÄÈ«¾Ö±äÁ¿¼°Æä³õʼ»¯Öµ
ºÍº¯ÊýÉùÃ÷
1.server.cppÖУº
ÒýÓÃ
£º
#include "clientp2p.h"
int Main(....)
{
...
}
2.clientp2p.cpp
ÖУ¬
Ò²ÒýÓÃ
£º
#include
"clientp2p.h"
....
3. file_2.cpp
#include "global.h"
...
G£«£«ÔÚ±àÒëµÄʱºò¾Í»á³ö´í£º
clientp2p.o:(.bss+0x0): multiple definition of `ClientList'
server.o:(.bss+0x0): first defined here
ÔÒòÊÇÒòΪÔÚ¶à´Î°üº¬
clientp2p
.hʱÖظ´¶¨ÒåÁ˱äÁ¿ºÍº¯Êý¡£
½â¾ö·½·¨£º
·½·¨Ò»£º
ÔÚ
clientp2p
.c£¨»ò.cpp) ÖÐÉùÃ÷±äÁ¿£¨²»³õʼ»¯£©£¬È»ºóÍ·Îļþ
clientp2p
.hÖÐÔÚËùÓеıäÁ¿ÉùÃ÷Ç°¼ÓÉÏextern
Èç extern int flag;
È»ºóÔÚÆäËûÐèҪʹÓÃÈ«¾Ö±äÁ¿µÄ cppÎļþÖаüº¬.h Îļþ¶ø²»Òª°üº¬ .cpp Îļþ¡£±àÒëÆ÷»áΪglobal.cpp Éú³ÉÄ¿±êÎļþ£¬È»ºóÁ¬½Óʱ£¬ÔÚʹÓÃÈ«¾Ö±äÁ¿µÄÎļþÖоͻáÁ¬½Óµ½´ËÎļþ ¡£
·½·¨¶þ£º
ÔÚ
clientp2p
.hÖмÓÈë·ÀÖ¹¶à´ÎÖظ´¶¨ÒåµÄºêÅжϷûºÅ
ÄãµÄ.HÀïÃæÒª¼ÓÉÏÌõ¼þ±àÒë
#ifndef GLOBAL
#define GLOBAL
XXXXX
XXXXX
#endif
¼Çס£ºÔÚifndefʱһ¶¨ÒªÔÚµÚÒ»ÐУ¬Ç°±ß²»ÒªÓÐÈκεÄ×¢ÊÍ»òÓï¾ä¡£
¶þ:
undefined reference to `std::ios_base::Init::Init() ½â¾ö
ÔÚlinuxϱàÒëc++ ³ÌÐòҪʹÓÃg++ ±àÒëÆ÷,Èç¹ûÄãÒªÊÇʹÓÃgcc±àÒëÆ÷¾Í»áÓÐÉÏÃæµÄ±¨´íÐÅÏ¢,Ö»ÒªÔÚÔÚgccºó¼ÓÉÏ -lstdc++¾ÍokÁË
eg: gcc example.c -lstdc++
Ïà¹ØÎĵµ£º
2009-07-26 15:50
½ñÌìÇÞÊÒµÄɽ¶«ÐÖµÜÔÚÁ·¶þ¼¶µÄÉÏ»ú£¬ÆäÖÐÒ»¸öÌâÄ¿´ó¸ÅÊÇÕâÑù£ºÔÚÒ»¸öº¯ÊýÖУ¬ÓÐÒ»¸öÖ¸ÕëÐβΣ¬¼ÇΪ*p£¬È»ºóÔÚº¯ÊýÄÚ²¿¶¨ÒåÁËÁÙʱ±äÁ¿a,aºÍ*pÊÇͬÖÖÀàÐÍ¡£¾¹ýһϵÁмÆËã £¬aµÃµ½ÁËÒ»¸öÖµ£¬Õâ¸öÖµ×îºóÊÇÐèÒª¼Ç¼ÔÚÖ¸Õë*pÀïÃæµÄ£¬Ó¦¸ÃÔõô±£´æÄØ£¿ÎÒµ±Ê±Ëæ±ã¾Í˵£¬p=&a¡£½á¹û·¢Éú´íÎóÁË£¬Ã»Óе ......
Ç°¼¸Ìì²Î¼Óij¹«Ë¾µÄ±ÊÊÔ£¬ÓÐÒ»µÀÌâÊÇÓô¿CʵÏÖÒ»¸ö·ºÐͺ¯Êý¡£ÓôÃÆÁ˺þÃÓÃC++Ä£°åʵÏÖÁË¡£
ºêÓÐÈçϵÄÌص㣺
1.ÓëconstÏà±È£¬ºêÊÇÔÚÔ¤±àÒëµÄʱºòÍê³ÉµÄ
2.define Ö»×ö¼òµ¥µÄÌæ»»£¬²»×öÀàÐÍ°²È«¼ì²é
3.ʹÓò»µ±»áÒýÆðºÜ¶àÎÊÌâ
ºêµÄÓ÷¨£º
1.¼òµ¥µÄºê¶¨Òå
#define MAX 1024
2.ºê¶¨Ò幦ÄÜ¿é
#define MAX(a,b) ( ......
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
int main()
{
char a = 'a';
......
C/C++/VC++ ±äÁ¿ÃüÃû¹æÔò
ÊÇVC++µÄô£¿
4.±äÁ¿·ç¸ñ
±äÁ¿¾¡Á¿²ÉÓÃÐÙÑÀÀûÃüÃû·¨£¬Í¬Ê±½áºÏVCµÄÔÔò£»Ò»°ãÇé¿öÏ£¬±äÁ¿µÄÈ¡Ãû·½Ê½Îª£º
<scope><prefix><qualifier>
ÓйØÏîÄ¿µÄÈ«¾Ö±äÁ¿±ØÐëÓÃg_¿ªÊ¼£¬Àà³ÉÔ±±äÁ¿ÓÃm_£¬¾Ö²¿±äÁ¿Èôº¯Êý½Ï´óÔò¿É¿¼ÂÇÓÃl_ÓÃÒÔÏÔʾ˵Ã÷ÆäÊǾֲ¿±äÁ¿¡£
ǰ׺
ÀàÐÍ
ʾÀý
g_
......