I'm trying to get this:
我想要这个:
//C.h
#ifndef C_H
#define C_H
#include "c.h"
class C
{
public:
C();
int function(int, int);
};
#endif
which is defined in this:
其定义如下:
//c.cpp
#include "c.h"
C::C()
{
}
int C::function(int a, int b)
{
return a * b;
}
to work in this:
在这工作:
//crp.cpp
#include <iostream>
#include "c.h"
void main(void)
{
C a;
std::cout << a.function(1, 2);
}
but I get two errors
但我得到两个错误
Error: Unresolved external 'C::C()' referenced from C:\C++\CRP.OBJ
错误:从C:\ C ++ \ CRP.OBJ引用的未解析的外部'C :: C()'
Error: Unresolved external 'C::function(int, int)' referenced from C:\C++\CRP.OBJ
错误:从C:\ C ++ \ CRP.OBJ引用的未解析的外部'C :: function(int,int)'
I'm really stuck. Help v. much appreciated!
我真的被卡住了。帮助v。非常感谢!
EDIT:
Thank you for your replies,
谢谢您的回复,
I'm using Borland C++ 5.5.1 for Win32, via the command line, I'm not actually sure what a linker is, this is the first time I've tried doing this.
我正在使用Borland C ++ 5.5.1 for Win32,通过命令行,我真的不确定链接器是什么,这是我第一次尝试这样做。
5 个解决方案
#1
3
It looks like your link phase is trying to create an executable from just crp.obj, NOT crp.obj and c.obj.
看起来您的链接阶段正在尝试从crp.obj,而不是crp.obj和c.obj创建可执行文件。
How are you compling it? It should be something like (in the case of Borland, as mentioned in edit):
你是如何编写它的?它应该是类似的(在Borland的情况下,如编辑中所提到的):
bcc32 -ecrp.exe crp.cpp c.cpp
You also don't need the include line within c.h, the only thing stopping an infinite include loop there is the include guard.
你也不需要c.h中的include行,唯一阻止无限include循环的是include guard。
#2
1
When you link your program you need to link both the c.obj file and the crp.obj file. The error you are seeing is because only the crp.obj file is being used for the link.
链接程序时,需要链接c.obj文件和crp.obj文件。您看到的错误是因为只有crp.obj文件用于链接。
What compiler are you using? If you are using something like VisualStudio then if both c.cpp and crp.cpp are in the same project it should work. If you are using the command line to build then you need to link both files, eg
你用的是什么编译器?如果你使用像VisualStudio这样的东西,那么如果c.cpp和crp.cpp都在同一个项目中,它应该可以工作。如果您使用命令行进行构建,则需要链接这两个文件,例如
gcc -o crp.exe c.cpp crp.cpp
gcc -o crp.exe c.cpp crp.cpp
for gcc
#3
0
Which compiler / development environment are you using? Is this from the command line or an IDE?
您使用的是哪种编译器/开发环境?这是从命令行还是IDE?
You need to make sure you compile c.cpp and tell the linker to include c.obj together with crp.obj to create your executable.
您需要确保编译c.cpp并告诉链接器将c.obj与crp.obj一起包含以创建可执行文件。
#4
0
Hmm...which compiler/linker do you use? Arguments provided to linker? Are the files part of the same project?
嗯......你使用哪个编译器/链接器?提供给链接器的参数?这些文件是同一个项目的一部分吗?
#5
0
Thank you for your replies,
谢谢您的回复,
I'm using Borland C++ 5.5.1 for Win32, via the command line, I'm not actually sure what a linker is, this is the first time I've tried doing this.
我正在使用Borland C ++ 5.5.1 for Win32,通过命令行,我真的不确定链接器是什么,这是我第一次尝试这样做。
EDIT:
** This is what I was trying before in the windows Command Prompt:
**这是我之前在Windows命令提示符中尝试的内容:
C:\c++>bcc32 crp
**And this was the result:
**这就是结果:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
crp.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'C::C()' referenced from C:\C++\CRP.OBJ
Error: Unresolved external 'C::function(int, int)' referenced from C:\C++\CRP.OBJ
** Then I tried this:
**然后我尝试了这个:
bcc32 -ecrp.exe crp.cpp c.cpp
**as Pax Diablo suggested, and got this :
**正如Pax Diablo建议的那样,得到了这个:
C:\c++>bcc32 -ecrp.exe crp.cpp c.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
crp.cpp:
c.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
**but on trying to compile crp.cpp once more, I got the same error as before:
**但是在尝试再次编译crp.cpp时,我得到了和以前一样的错误:
C:\c++>bcc32 crp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
crp.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'C::C()' referenced from C:\C++\CRP.OBJ
Error: Unresolved external 'C::function(int, int)' referenced from C:\C++\CRP.OBJ
EDIT: Oops! Trying to compile it the wrong way again was pretty silly of me. It works now though. So the solution is, as Pax Diablo orginally suggested, to compile crp.cpp like this:
编辑:哎呀!试图以错误的方式再次编译它对我来说非常愚蠢。它虽然现在有效。因此,正如Pax Diablo建议的那样,解决方案是编译crp.cpp,如下所示:
bcc32 -ecrp.exe crp.cpp c.cpp
Problem solved, thanks to everyone who replied!
问题解决了,感谢所有回复的人!
#1
3
It looks like your link phase is trying to create an executable from just crp.obj, NOT crp.obj and c.obj.
看起来您的链接阶段正在尝试从crp.obj,而不是crp.obj和c.obj创建可执行文件。
How are you compling it? It should be something like (in the case of Borland, as mentioned in edit):
你是如何编写它的?它应该是类似的(在Borland的情况下,如编辑中所提到的):
bcc32 -ecrp.exe crp.cpp c.cpp
You also don't need the include line within c.h, the only thing stopping an infinite include loop there is the include guard.
你也不需要c.h中的include行,唯一阻止无限include循环的是include guard。
#2
1
When you link your program you need to link both the c.obj file and the crp.obj file. The error you are seeing is because only the crp.obj file is being used for the link.
链接程序时,需要链接c.obj文件和crp.obj文件。您看到的错误是因为只有crp.obj文件用于链接。
What compiler are you using? If you are using something like VisualStudio then if both c.cpp and crp.cpp are in the same project it should work. If you are using the command line to build then you need to link both files, eg
你用的是什么编译器?如果你使用像VisualStudio这样的东西,那么如果c.cpp和crp.cpp都在同一个项目中,它应该可以工作。如果您使用命令行进行构建,则需要链接这两个文件,例如
gcc -o crp.exe c.cpp crp.cpp
gcc -o crp.exe c.cpp crp.cpp
for gcc
#3
0
Which compiler / development environment are you using? Is this from the command line or an IDE?
您使用的是哪种编译器/开发环境?这是从命令行还是IDE?
You need to make sure you compile c.cpp and tell the linker to include c.obj together with crp.obj to create your executable.
您需要确保编译c.cpp并告诉链接器将c.obj与crp.obj一起包含以创建可执行文件。
#4
0
Hmm...which compiler/linker do you use? Arguments provided to linker? Are the files part of the same project?
嗯......你使用哪个编译器/链接器?提供给链接器的参数?这些文件是同一个项目的一部分吗?
#5
0
Thank you for your replies,
谢谢您的回复,
I'm using Borland C++ 5.5.1 for Win32, via the command line, I'm not actually sure what a linker is, this is the first time I've tried doing this.
我正在使用Borland C ++ 5.5.1 for Win32,通过命令行,我真的不确定链接器是什么,这是我第一次尝试这样做。
EDIT:
** This is what I was trying before in the windows Command Prompt:
**这是我之前在Windows命令提示符中尝试的内容:
C:\c++>bcc32 crp
**And this was the result:
**这就是结果:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
crp.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'C::C()' referenced from C:\C++\CRP.OBJ
Error: Unresolved external 'C::function(int, int)' referenced from C:\C++\CRP.OBJ
** Then I tried this:
**然后我尝试了这个:
bcc32 -ecrp.exe crp.cpp c.cpp
**as Pax Diablo suggested, and got this :
**正如Pax Diablo建议的那样,得到了这个:
C:\c++>bcc32 -ecrp.exe crp.cpp c.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
crp.cpp:
c.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
**but on trying to compile crp.cpp once more, I got the same error as before:
**但是在尝试再次编译crp.cpp时,我得到了和以前一样的错误:
C:\c++>bcc32 crp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
crp.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'C::C()' referenced from C:\C++\CRP.OBJ
Error: Unresolved external 'C::function(int, int)' referenced from C:\C++\CRP.OBJ
EDIT: Oops! Trying to compile it the wrong way again was pretty silly of me. It works now though. So the solution is, as Pax Diablo orginally suggested, to compile crp.cpp like this:
编辑:哎呀!试图以错误的方式再次编译它对我来说非常愚蠢。它虽然现在有效。因此,正如Pax Diablo建议的那样,解决方案是编译crp.cpp,如下所示:
bcc32 -ecrp.exe crp.cpp c.cpp
Problem solved, thanks to everyone who replied!
问题解决了,感谢所有回复的人!