首先,我写了一个简单程序makefold.cpp
源代码:
#include<iostream>
uisng namespace std;
int main()
{
cout<<"OK"<<endl;
return 0;
}
然后写了一个makefile文件
makefold.exe:makefold.bak
g++ -o makefold.exe makefold.bak
makefold.bak:makefold.cpp
g++ -o makefold.bak makefold.cpp
clean:
rm makefold.bak makefold.exe
接着打开cmd:输入make之后出现如下错误:
g++ -o makefold.bak makefold.cpp
makefold.cpp:2: error: expected constructor, destructor, or type conversion before "namespace"
makefold.cpp:2: error: expected `,' or `;' before "namespace"
makefold.cpp: In function `int main()':
makefold.cpp:5: error: `cout' undeclared (first use this function)
makefold.cpp:5: error: (Each undeclared identifier is reported only once for each function it appears in.)
makefold.cpp:5: error: `endl' undeclared (first use this function)
make: *** [makefold.bak] Error 1
请大虾们指点
9 个解决方案
#1
uisng namespace std;
改成:
using namespace std;
改成:
using namespace std;
#2
#include <iostream>
using namespace std;
int main()
{
cout << "OK" << endl;
return 0;
}
你代码错了。
#3
另,CodeLite可以生成makefile,很爽啊,看:
[code=BatchFile]##
## Auto Generated makefile, please do not edit
##
PATH:=$(PATH);D:\qpdev\bin
WXWIN:=E:\wxMSW-2009-06-06
WXCFG:=gcc_lib\mswu
ProjectName:=makefold
## Debug
ConfigurationName :=Debug
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
LinkerName:=g++
ArchiveTool :=ar rcus
SharedObjectLinkerName :=g++ -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=
DebugSwitch :=-gstab
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
CompilerName :=g++
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=
CmpOptions := -g $(Preprocessors)
LinkOptions :=
IncludePath := "$(IncludeSwitch)." "$(IncludeSwitch)."
RcIncludePath :=
Libs :=
LibPath := "$(LibraryPathSwitch)."
Objects=$(IntermediateDirectory)/main$(ObjectSuffix)
##
## Main Build Tragets
##
all: $(OutputFile)
$(OutputFile): makeDirStep $(Objects)
@makedir $(@D)
$(LinkerName) $(OutputSwitch)$(OutputFile) $(Objects) $(LibPath) $(Libs) $(LinkOptions)
makeDirStep:
@makedir "./Debug"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/main$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main$(DependSuffix)
@makedir "./Debug"
$(CompilerName) $(SourceSwitch) "Z:/makefold/main.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/main$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main$(DependSuffix): main.cpp
@makedir "./Debug"
@$(CompilerName) $(CmpOptions) $(IncludePath) -MT$(IntermediateDirectory)/main$(ObjectSuffix) -MF$(IntermediateDirectory)/main$(DependSuffix) -MM "Z:/makefold/main.cpp"
##
## Clean
##
clean:
$(RM) $(IntermediateDirectory)/main$(ObjectSuffix)
$(RM) $(IntermediateDirectory)/main$(DependSuffix)
$(RM) $(IntermediateDirectory)/main$(PreprocessSuffix)
$(RM) $(OutputFile)
$(RM) $(OutputFile).exe
-include $(IntermediateDirectory)/*$(DependSuffix)
[/code]
[code=BatchFile]##
## Auto Generated makefile, please do not edit
##
PATH:=$(PATH);D:\qpdev\bin
WXWIN:=E:\wxMSW-2009-06-06
WXCFG:=gcc_lib\mswu
ProjectName:=makefold
## Debug
ConfigurationName :=Debug
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
LinkerName:=g++
ArchiveTool :=ar rcus
SharedObjectLinkerName :=g++ -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=
DebugSwitch :=-gstab
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
CompilerName :=g++
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=
CmpOptions := -g $(Preprocessors)
LinkOptions :=
IncludePath := "$(IncludeSwitch)." "$(IncludeSwitch)."
RcIncludePath :=
Libs :=
LibPath := "$(LibraryPathSwitch)."
Objects=$(IntermediateDirectory)/main$(ObjectSuffix)
##
## Main Build Tragets
##
all: $(OutputFile)
$(OutputFile): makeDirStep $(Objects)
@makedir $(@D)
$(LinkerName) $(OutputSwitch)$(OutputFile) $(Objects) $(LibPath) $(Libs) $(LinkOptions)
makeDirStep:
@makedir "./Debug"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/main$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main$(DependSuffix)
@makedir "./Debug"
$(CompilerName) $(SourceSwitch) "Z:/makefold/main.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/main$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main$(DependSuffix): main.cpp
@makedir "./Debug"
@$(CompilerName) $(CmpOptions) $(IncludePath) -MT$(IntermediateDirectory)/main$(ObjectSuffix) -MF$(IntermediateDirectory)/main$(DependSuffix) -MM "Z:/makefold/main.cpp"
##
## Clean
##
clean:
$(RM) $(IntermediateDirectory)/main$(ObjectSuffix)
$(RM) $(IntermediateDirectory)/main$(DependSuffix)
$(RM) $(IntermediateDirectory)/main$(PreprocessSuffix)
$(RM) $(OutputFile)
$(RM) $(OutputFile).exe
-include $(IntermediateDirectory)/*$(DependSuffix)
[/code]
#4
呃,楼主粗心了。
uisng namespace std;
改为using namespace std;
uisng namespace std;
改为using namespace std;
#5
呵呵,是我打错了,但是不是那个原因~
#6
= =||| 哎,不是那个原因,我运行的代码里面那个没有错~
#7
修改过来了:
但是有以下错误
make
g++ -o makefold.exe makefold.bak
makefold.bak(.text+0x220):locale-misc-inst.cc: multiple definition of `mainCRTSt
artup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x220):crt1.c: fir
st defined here
makefold.bak(.text+0x240):locale-misc-inst.cc: multiple definition of `WinMainCR
TStartup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x240):crt1.c: fir
st defined here
makefold.bak(.text+0x260):locale-misc-inst.cc: multiple definition of `atexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x260):crt1.c: fir
st defined here
makefold.bak(.text+0x270):locale-misc-inst.cc: multiple definition of `_onexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x270):crt1.c: fir
st defined here
makefold.bak(.text+0x280):locale-misc-inst.cc: multiple definition of `__do_sjlj
_init'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/crtbegin.o(.text+0x0):crtstuff.c: first
defined here
makefold.bak(.bss+0x4):crtstuff.c: multiple definition of `_argc'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x4):crt1.c: first
defined here
makefold.bak(.bss+0x0):crtstuff.c: multiple definition of `_argv'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x0):crt1.c: first
defined here
collect2: ld returned 1 exit status
make: *** [makefold.exe] Error 1
但是有以下错误
make
g++ -o makefold.exe makefold.bak
makefold.bak(.text+0x220):locale-misc-inst.cc: multiple definition of `mainCRTSt
artup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x220):crt1.c: fir
st defined here
makefold.bak(.text+0x240):locale-misc-inst.cc: multiple definition of `WinMainCR
TStartup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x240):crt1.c: fir
st defined here
makefold.bak(.text+0x260):locale-misc-inst.cc: multiple definition of `atexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x260):crt1.c: fir
st defined here
makefold.bak(.text+0x270):locale-misc-inst.cc: multiple definition of `_onexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x270):crt1.c: fir
st defined here
makefold.bak(.text+0x280):locale-misc-inst.cc: multiple definition of `__do_sjlj
_init'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/crtbegin.o(.text+0x0):crtstuff.c: first
defined here
makefold.bak(.bss+0x4):crtstuff.c: multiple definition of `_argc'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x4):crt1.c: first
defined here
makefold.bak(.bss+0x0):crtstuff.c: multiple definition of `_argv'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x0):crt1.c: first
defined here
collect2: ld returned 1 exit status
make: *** [makefold.exe] Error 1
#8
makefold.exe:makefold.bak
g++ -o makefold.exe makefold.bak
makefold.bak:makefold.cpp
g++ -c -o makefold.bak makefold.cpp #加了个-c
clean:
rm makefold.bak makefold.exe
g++ -o makefold.exe makefold.bak
makefold.bak:makefold.cpp
g++ -c -o makefold.bak makefold.cpp #加了个-c
clean:
rm makefold.bak makefold.exe
#9
总算解决了,bak文件是备份文件,我当做链接文件了~ 晕
makefold.exe:makefold.o
g++ -o makefold.exe makefold.o
makefold.o:makefold.cpp
g++ -c makefold.cpp
clean:
-rm makefold.bak makefold.exe makefold.o
这样就好了
解决了,谢谢大家
makefold.exe:makefold.o
g++ -o makefold.exe makefold.o
makefold.o:makefold.cpp
g++ -c makefold.cpp
clean:
-rm makefold.bak makefold.exe makefold.o
这样就好了
解决了,谢谢大家
#1
uisng namespace std;
改成:
using namespace std;
改成:
using namespace std;
#2
#include <iostream>
using namespace std;
int main()
{
cout << "OK" << endl;
return 0;
}
你代码错了。
#3
另,CodeLite可以生成makefile,很爽啊,看:
[code=BatchFile]##
## Auto Generated makefile, please do not edit
##
PATH:=$(PATH);D:\qpdev\bin
WXWIN:=E:\wxMSW-2009-06-06
WXCFG:=gcc_lib\mswu
ProjectName:=makefold
## Debug
ConfigurationName :=Debug
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
LinkerName:=g++
ArchiveTool :=ar rcus
SharedObjectLinkerName :=g++ -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=
DebugSwitch :=-gstab
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
CompilerName :=g++
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=
CmpOptions := -g $(Preprocessors)
LinkOptions :=
IncludePath := "$(IncludeSwitch)." "$(IncludeSwitch)."
RcIncludePath :=
Libs :=
LibPath := "$(LibraryPathSwitch)."
Objects=$(IntermediateDirectory)/main$(ObjectSuffix)
##
## Main Build Tragets
##
all: $(OutputFile)
$(OutputFile): makeDirStep $(Objects)
@makedir $(@D)
$(LinkerName) $(OutputSwitch)$(OutputFile) $(Objects) $(LibPath) $(Libs) $(LinkOptions)
makeDirStep:
@makedir "./Debug"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/main$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main$(DependSuffix)
@makedir "./Debug"
$(CompilerName) $(SourceSwitch) "Z:/makefold/main.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/main$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main$(DependSuffix): main.cpp
@makedir "./Debug"
@$(CompilerName) $(CmpOptions) $(IncludePath) -MT$(IntermediateDirectory)/main$(ObjectSuffix) -MF$(IntermediateDirectory)/main$(DependSuffix) -MM "Z:/makefold/main.cpp"
##
## Clean
##
clean:
$(RM) $(IntermediateDirectory)/main$(ObjectSuffix)
$(RM) $(IntermediateDirectory)/main$(DependSuffix)
$(RM) $(IntermediateDirectory)/main$(PreprocessSuffix)
$(RM) $(OutputFile)
$(RM) $(OutputFile).exe
-include $(IntermediateDirectory)/*$(DependSuffix)
[/code]
[code=BatchFile]##
## Auto Generated makefile, please do not edit
##
PATH:=$(PATH);D:\qpdev\bin
WXWIN:=E:\wxMSW-2009-06-06
WXCFG:=gcc_lib\mswu
ProjectName:=makefold
## Debug
ConfigurationName :=Debug
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
LinkerName:=g++
ArchiveTool :=ar rcus
SharedObjectLinkerName :=g++ -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=
DebugSwitch :=-gstab
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
CompilerName :=g++
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=
CmpOptions := -g $(Preprocessors)
LinkOptions :=
IncludePath := "$(IncludeSwitch)." "$(IncludeSwitch)."
RcIncludePath :=
Libs :=
LibPath := "$(LibraryPathSwitch)."
Objects=$(IntermediateDirectory)/main$(ObjectSuffix)
##
## Main Build Tragets
##
all: $(OutputFile)
$(OutputFile): makeDirStep $(Objects)
@makedir $(@D)
$(LinkerName) $(OutputSwitch)$(OutputFile) $(Objects) $(LibPath) $(Libs) $(LinkOptions)
makeDirStep:
@makedir "./Debug"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/main$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main$(DependSuffix)
@makedir "./Debug"
$(CompilerName) $(SourceSwitch) "Z:/makefold/main.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/main$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main$(DependSuffix): main.cpp
@makedir "./Debug"
@$(CompilerName) $(CmpOptions) $(IncludePath) -MT$(IntermediateDirectory)/main$(ObjectSuffix) -MF$(IntermediateDirectory)/main$(DependSuffix) -MM "Z:/makefold/main.cpp"
##
## Clean
##
clean:
$(RM) $(IntermediateDirectory)/main$(ObjectSuffix)
$(RM) $(IntermediateDirectory)/main$(DependSuffix)
$(RM) $(IntermediateDirectory)/main$(PreprocessSuffix)
$(RM) $(OutputFile)
$(RM) $(OutputFile).exe
-include $(IntermediateDirectory)/*$(DependSuffix)
[/code]
#4
呃,楼主粗心了。
uisng namespace std;
改为using namespace std;
uisng namespace std;
改为using namespace std;
#5
呵呵,是我打错了,但是不是那个原因~
#6
= =||| 哎,不是那个原因,我运行的代码里面那个没有错~
#7
修改过来了:
但是有以下错误
make
g++ -o makefold.exe makefold.bak
makefold.bak(.text+0x220):locale-misc-inst.cc: multiple definition of `mainCRTSt
artup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x220):crt1.c: fir
st defined here
makefold.bak(.text+0x240):locale-misc-inst.cc: multiple definition of `WinMainCR
TStartup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x240):crt1.c: fir
st defined here
makefold.bak(.text+0x260):locale-misc-inst.cc: multiple definition of `atexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x260):crt1.c: fir
st defined here
makefold.bak(.text+0x270):locale-misc-inst.cc: multiple definition of `_onexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x270):crt1.c: fir
st defined here
makefold.bak(.text+0x280):locale-misc-inst.cc: multiple definition of `__do_sjlj
_init'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/crtbegin.o(.text+0x0):crtstuff.c: first
defined here
makefold.bak(.bss+0x4):crtstuff.c: multiple definition of `_argc'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x4):crt1.c: first
defined here
makefold.bak(.bss+0x0):crtstuff.c: multiple definition of `_argv'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x0):crt1.c: first
defined here
collect2: ld returned 1 exit status
make: *** [makefold.exe] Error 1
但是有以下错误
make
g++ -o makefold.exe makefold.bak
makefold.bak(.text+0x220):locale-misc-inst.cc: multiple definition of `mainCRTSt
artup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x220):crt1.c: fir
st defined here
makefold.bak(.text+0x240):locale-misc-inst.cc: multiple definition of `WinMainCR
TStartup'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x240):crt1.c: fir
st defined here
makefold.bak(.text+0x260):locale-misc-inst.cc: multiple definition of `atexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x260):crt1.c: fir
st defined here
makefold.bak(.text+0x270):locale-misc-inst.cc: multiple definition of `_onexit'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.text+0x270):crt1.c: fir
st defined here
makefold.bak(.text+0x280):locale-misc-inst.cc: multiple definition of `__do_sjlj
_init'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/crtbegin.o(.text+0x0):crtstuff.c: first
defined here
makefold.bak(.bss+0x4):crtstuff.c: multiple definition of `_argc'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x4):crt1.c: first
defined here
makefold.bak(.bss+0x0):crtstuff.c: multiple definition of `_argv'
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../crt2.o(.bss+0x0):crt1.c: first
defined here
collect2: ld returned 1 exit status
make: *** [makefold.exe] Error 1
#8
makefold.exe:makefold.bak
g++ -o makefold.exe makefold.bak
makefold.bak:makefold.cpp
g++ -c -o makefold.bak makefold.cpp #加了个-c
clean:
rm makefold.bak makefold.exe
g++ -o makefold.exe makefold.bak
makefold.bak:makefold.cpp
g++ -c -o makefold.bak makefold.cpp #加了个-c
clean:
rm makefold.bak makefold.exe
#9
总算解决了,bak文件是备份文件,我当做链接文件了~ 晕
makefold.exe:makefold.o
g++ -o makefold.exe makefold.o
makefold.o:makefold.cpp
g++ -c makefold.cpp
clean:
-rm makefold.bak makefold.exe makefold.o
这样就好了
解决了,谢谢大家
makefold.exe:makefold.o
g++ -o makefold.exe makefold.o
makefold.o:makefold.cpp
g++ -c makefold.cpp
clean:
-rm makefold.bak makefold.exe makefold.o
这样就好了
解决了,谢谢大家