473,769 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird Error in MinGW (Dev-C++)

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

Jan 6 '07 #1
10 2107
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:
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
Jan 6 '07 #2
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?

Jan 6 '07 #3
"JeffCamero n" <ca********@gma il.comwrote in message
news:11******** **************@ 38g2000cwa.goog legroups.com...
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?
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.
Jan 6 '07 #4
Yuu
It seems that some people LOVE to reply with: "your question should be
asked somewhere else"... :-(

I think you simply need:

extern "C"
{
void helloWorld();
}

Then your header will work in C++ but not in C anymore.
That's why one can find the following idiom in several C/C++ libraries:

#ifdef __cplusplus
extern "C"
{
#endif

void helloWorld();

#ifdef __cplusplus
}
#endif
Sorry if i mistyped something (i'm writing this idiom from memory), but
basically this is it.

Jan 6 '07 #5
Thanks Yuu. I'll try that.

You're right. I'm annoyed every time I see someone get rudely
dismissed with the age-old "this question doesn't belong here" reply.
There's just no point to that kind of behavior. Why not just answer
the question? And if you don't know the answer, then don't post. I'm
glad someone came along who actually knows the answer to my question.

Jeff Cameron

Jan 6 '07 #6
On Fri, 05 Jan 2007 22:43:45 -0800, JeffCameron wrote:
Thanks Yuu. I'll try that.

You're right. I'm annoyed every time I see someone get rudely
dismissed with the age-old "this question doesn't belong here" reply.
There's just no point to that kind of behavior. Why not just answer
the question? And if you don't know the answer, then don't post. I'm
glad someone came along who actually knows the answer to my question.
My dog has been a little off-colour lately and I suspect he may have
worms. What specific symptoms should I look for? (Please don't reply if
you don't know the answer).

;)

--
Lionel B
Jan 8 '07 #7
Lionel B wrote:
My dog has been a little off-colour lately and I suspect he may have
worms. What specific symptoms should I look for? (Please don't reply if
you don't know the answer).
42

--
Salu2
Jan 8 '07 #8
Yuu

Lionel B skribis:
On Fri, 05 Jan 2007 22:43:45 -0800, JeffCameron wrote:
Thanks Yuu. I'll try that.

You're right. I'm annoyed every time I see someone get rudely
dismissed with the age-old "this question doesn't belong here" reply.
There's just no point to that kind of behavior. Why not just answer
the question? And if you don't know the answer, then don't post. I'm
glad someone came along who actually knows the answer to my question.

My dog has been a little off-colour lately and I suspect he may have
worms. What specific symptoms should I look for? (Please don't reply if
you don't know the answer).

;)

--
Lionel B
But the OP's question wasn't off-topic after all (if my answer did
work). The fact that he put "MinGW" in the title doesn't make it
off-topic. Neither does the fact that he got a linker error (is there a
comp.lang.c++.l inkererrors? :-P). It's still C++, the only thing he
needed was an extern "C"...

Jan 8 '07 #9
Shawn McGrath wrote:
You are not linking helloWorld.c.
Of course, since C files are not linked. However, he was linking
helloWorld.o (or .obj).
1. This is a C question, not a C++ question.
His file was called "main.cpp", which suggests that it is 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.
There is no problem with his linker settings.
Please ask in the appropriate places.
This is the appropriate place. Please get a clue

Jan 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4474
by: Joe Helmick | last post by:
This weird error started showing up as I was developing an email-enabled program. Once it occurs, I cannot set breakpoints in my code. Quitting Visual Studio does not help, nor does restarting my machine. In desperation, I reinstalled the .NET framework 1.1 this morning, and the error didn't occur on the first few test runs of my program; I was getting happier. But then it started happening again! I cannot figure out how to make it...
3
4871
by: sean | last post by:
HI There, I am recieving a weird error when I try to run asp scripts on my local machine, I can use pages that access a database, but when I try to write to the file system ie upload a file I get the error message below. any ideas? Sean
1
2786
by: amit | last post by:
I am trying to compile the sample program genwin.sqc, using nsqlprep which is used to precompile embedded sql in C. I am getting weird errors and that is because windows.h is included in the genwin.sqc file. I am using Setting the lib and include path: set INCLUDE=C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\include;C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\esqlc;%include%
2
2744
by: Scott Reynolds | last post by:
I am having a problem exposing a class inherited from the collection base class as a webservice. If I expose the collection on a web page all works well and I am very happy. However when I try and expose this via a web service I get a weird error saying that the dll could not be found. The specific error is: I can't figure it out. I thought it was to do with reflection but I am able to load and view the webservice definition which...
2
1648
by: Hendrik Schober | last post by:
Hi, I have some expression template code that I want to get to work. I had a typo in it and just spent two hours to find it, because VC7.1 gave a really weird error message for it. This is the code: template< typename T1, typename TExpr, typename T2> inline
1
5899
by: Peter | last post by:
Hi, I am getting really weird error, when I try to load one of my ASP.NET website pages: Server Error in '/' Application. ----------------------------------------------------------- --------------------- There is not enough space on the disk.
6
1550
by: gh0st54 | last post by:
Hi I have a weird javascript error that only happens on my live server when i open the page http://www.imrated.co.uk/reg.aspx i get the error 'Problems with this page ... blablabla Line : 3 Char : 1 Error:Syntax error
3
2405
by: Dameon99 | last post by:
Hi.. Im experiencing a weird error I dont know how to fix. I have a scanner object and whenever I use nextInt, anything above 3 causes the program to crash saying and links me to this line of the class: (one I added all the asteriss to. // If we are at the end of input then NoSuchElement; // If there is still input left then InputMismatch private void throwFor() { skipped = false; if ((sourceClosed) &&...
4
2241
by: sundarvenkata | last post by:
Hi All, I wanted to develop a WPF application to capture the output of a command line program and display it in a GUI. However I get a weird error in the following code: System.Diagnostics.Process pfadminProc = new System.Diagnostics.Process(); pfadminProc.StartInfo = new
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.