QSort Compare Function LNK2001 Unresolved External Symbol Error

Posted on 2005-02-24
Medium Priority
Last Modified: 2012-06-22

I'm quite new to using Qsort function. Have encountered problem with this error

error C2664: 'qsort' : cannot convert parameter 4 from 'int (const void *,const void *)' to 'int (__cdecl *)(const void *,const void *)'

but managed to get everything work out after changing my compare function to say

int cmp(const *ptr1,const *ptr2) through the help of Nietod's advice found at

However, right now i'm encountering the above mentioned error. The error is as follow

qsorting.obj : error LNK2001: unresolved external symbol "int __cdecl cmp(void const *,void const *)" (?cmp@@YAHPBX0@Z)
Debug/PROGRAM.exe : fatal error LNK1120: 1 unresolved externals

what have i gone wrong ? Been debugging it for the day. just cant get anything working. Does anyone has a working experience on this ? Kind advice needed and tks a million!

Question by:ricola
LVL 48

Expert Comment

ID: 13391884
Please show your code.
LVL 30

Accepted Solution

Axter earned 320 total points
ID: 13391902
Hi ricola,
>> nt cmp(const *ptr1,const *ptr2)
It's missing the type.

It should have a type like the following:
int cmp(const void*ptr1,const void*ptr2)

Author Comment

ID: 13392124
Axter you are absolutely correct ! Was about to post my code until i saw your msg. Gosh this small mistake kill hours of my time.

Thanks a million!

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question