MinGW中的奇怪错误(Dev-C ++) [英] Weird Error in MinGW (Dev-C++)

查看:67
本文介绍了MinGW中的奇怪错误(Dev-C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在使用Dev-C ++附带的最新MinGW for

Windows。当我尝试从我写的库中调用某些函数时,我收到一个不可能的链接器错误。我绝对相信图书馆链接了

。我非常感谢某人的回复

谁知道这个问题的解决方案。


这是我的问题的简化版本。为了重现我正在讨论的

链接错误,请使用以下步骤:

- 使用Dev-C ++使用hello.c和hello创建静态库.h

- 使用main.cpp创建一个新的控制台应用程序项目

主要源文件

- 转到项目 - 项目选项 - 参数并单击Add

库或对象按钮

- 添加在步骤1中创建的库

- 尝试编译main.cpp


我得到的错误是:

[链接错误]未定义引用''helloWorld()''


以下是源文件:

### hello.c ###

#include" hello.h"


void helloWorld()

{

printf(Hello World!\ n);

}


### hello.h ###

#ifndef HELLO_H

#define HELLO_H


#include< stdio.h>


void helloWorld();


#endif

### main.cpp ###

#include" hello.h"


int main()

{

helloWorld();

返回0;

}


我非常感谢知道解决方案的人的回复

来解决这个问题。

Jeff Cameron

Hi everyone. I am using the latest MinGW that comes with Dev-C++ for
Windows. I am getting an impossible linker error when I try to call
some functions from a library that I wrote. I am avsolutely sure that
the library is linked. I would greatly appreciate a reply from someone
who knows the solution to this problem.

Here is a simplified version of my problem. In order to reproduce the
linking error that I am talking about, use the following steps:
- Use Dev-C++ to create a static library using hello.c and hello.h
- Create a new console application project with main.cpp as its
main source file
- Go to Project -Project Options -Parameters and click the Add
Library or Object button
- Add the library that was created in step 1
- Attempt to compile main.cpp

The error that I get is:
[Linker error] undefined reference to ''helloWorld()''

Here are the source files:
### hello.c ###
#include "hello.h"

void helloWorld()
{
printf("Hello World!\n");
}

### hello.h ###
#ifndef HELLO_H
#define HELLO_H

#include <stdio.h>

void helloWorld();

#endif

### main.cpp ###
#include "hello.h"

int main()
{
helloWorld();
return 0;
}

I would greatly appreciate a reply from someone who knows the solution
to this problem.

Jeff Cameron

推荐答案

您没有链接helloWorld.c。


1.这是一个C问题,而不是C ++问题。

2.你的链接器设置不是C或C ++,它们是Dev-C ++,而且是

扩展MinGW和进一步扩展gcc问题。


请在适当的地方询问。


-Shawn。

JeffCameron写道:
You are not linking helloWorld.c.

1. This is a C question, not a C++ question.
2. Your linker settings are not C or C++, they are Dev-C++, and by
extension MinGW and by further extension gcc problems.

Please ask in the appropriate places.

-Shawn.

JeffCameron wrote:

大家好。我正在使用Dev-C ++附带的最新MinGW for

Windows。当我尝试从我写的库中调用某些函数时,我收到一个不可能的链接器错误。我绝对相信图书馆链接了

。我非常感谢某人的回复

谁知道这个问题的解决方案。


这是我的问题的简化版本。为了重现我正在讨论的

链接错误,请使用以下步骤:

- 使用Dev-C ++使用hello.c和hello创建静态库.h

- 使用main.cpp创建一个新的控制台应用程序项目

主要源文件

- 转到项目 - 项目选项 - 参数并单击Add

库或对象按钮

- 添加在步骤1中创建的库

- 尝试编译main.cpp


我得到的错误是:

[链接错误]未定义引用''helloWorld()''


以下是源文件:

### hello.c ###

#include" hello.h"


void helloWorld()

{

printf(Hello World!\ n);

}


### hello.h ###

#ifndef HELLO_H

#define HELLO_H


#include< stdio.h>


v oid helloWorld();


#endif


### main.cpp ###

#include " hello.h"


int main()

{

helloWorld();

返回0;

}


我非常感谢知道解决方案的人的回复

来解决这个问题。


Jeff Cameron
Hi everyone. I am using the latest MinGW that comes with Dev-C++ for
Windows. I am getting an impossible linker error when I try to call
some functions from a library that I wrote. I am avsolutely sure that
the library is linked. I would greatly appreciate a reply from someone
who knows the solution to this problem.

Here is a simplified version of my problem. In order to reproduce the
linking error that I am talking about, use the following steps:
- Use Dev-C++ to create a static library using hello.c and hello.h
- Create a new console application project with main.cpp as its
main source file
- Go to Project -Project Options -Parameters and click the Add
Library or Object button
- Add the library that was created in step 1
- Attempt to compile main.cpp

The error that I get is:
[Linker error] undefined reference to ''helloWorld()''

Here are the source files:
### hello.c ###
#include "hello.h"

void helloWorld()
{
printf("Hello World!\n");
}

### hello.h ###
#ifndef HELLO_H
#define HELLO_H

#include <stdio.h>

void helloWorld();

#endif

### main.cpp ###
#include "hello.h"

int main()
{
helloWorld();
return 0;
}

I would greatly appreciate a reply from someone who knows the solution
to this problem.

Jeff Cameron


我害怕你不明白我的问题,Shawn。链接hello.c

显然可以解决问题。但是,我已经单独编译了hello.c

并将其转换为库。我想将这个库

链接到最终的应用程序。任何人都可以解决我的问题吗?

I''m afraid you didn''t understand my question, Shawn. Linking hello.c
would obviously fix the problem. However, I have compiled hello.c
separately and turned it into a library. I want to link this library
to the final aplication. Can anyone solve my problem?


" JeffCameron" < ca ******** @ gmail.comwrote in message

news:11 ********************** @ 38g2000cwa.googlegro ups.com ...
"JeffCameron" <ca********@gmail.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...

我害怕你不明白我的问题,Shawn。链接hello.c

显然可以解决问题。但是,我已经单独编译了hello.c

并将其转换为库。我想将这个库

链接到最终的应用程序。谁能解决我的问题?
I''m afraid you didn''t understand my question, Shawn. Linking hello.c
would obviously fix the problem. However, I have compiled hello.c
separately and turned it into a library. I want to link this library
to the final aplication. Can anyone solve my problem?



实际上,他的回答是针对这个确切的问题。您没有C或C ++

问题但链接器问题,我想将此库链接到最终的

应用程序。


引用:

" 2。您的链接器设置不是C或C ++,它们是Dev-C ++,并且通过

扩展名MinGW以及进一步扩展gcc问题。


在一个gcc新闻组,你会得到答案。


comp.lang.c ++用于c ++语言问题/答案/讨论,由

定义标准,而不是特定的编译器/链接器。

Actually, his reply is to this exact problem. You do not have a C or a C++
problem but a linker problem, "I want to link this library to the final
application."

Quote:
"2. Your linker settings are not C or C++, they are Dev-C++, and by
extension MinGW and by further extension gcc problems."

Ask in a gcc newsgroup, and you''ll get an answer.

comp.lang.c++ is for c++ language question/answer/discussions as defined by
the standard, not specific compilers/linkers.


这篇关于MinGW中的奇怪错误(Dev-C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆