473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2065
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
"JeffCameron" <ca********@gmail.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.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++.linkererrors? :-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
On Mon, 08 Jan 2007 12:46:07 -0800, Yuu wrote:
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).

;)

But the OP's question wasn't off-topic after all
It may or may not have been... not the point. My facetious reply was in
response to his little rant quoted above.

This is a high-volume newsgroup. If it becomes inundated with OT postings,
that serves no-one well. In this case it was not at all clear (to me
and evidently to others too) from the original posting whether the query
was in fact on or off topic; a cursory reading by the OP of the "how to
post" section in the FAQ would quite likely have avoided this situation.

--
Lionel B
Jan 9 '07 #11

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

Similar topics

0
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...
3
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...
1
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...
2
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...
2
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...
1
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. -----------------------------------------------------------...
6
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...
3
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...
4
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: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.