[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

LNK2001 Error. Using a .lib

I am trying to use a .lib file to play mp3's for a project I am working on. It is the libmad.lib file. I am getting the error below when using it in a MSVC++ MFC Dialog project, but not in the standard MAD player console project that comes with the library. I have all of the librarys included in the project. I should also mention that the libmad.lib library is written in C and not CPP. What should I check for, I've been looking for a while now and my brain is fried.

GUIDlg.obj : error LNK2001: unresolved external symbol "void __cdecl player_finish(struct player *)" (?player_finish@@YAXPAUplayer@@@Z)
GUIDlg.obj : error LNK2001: unresolved external symbol "int __cdecl player_run(struct player *,int,char const * * const)" (?player_run@@YAHPAUplayer@@HQAPBD@Z)
GUIDlg.obj : error LNK2001: unresolved external symbol "int (__cdecl*__cdecl audio_output(char const * *))(union audio_control *)" (?audio_output@@YAP6AHPATaudio_control@@@ZPAPBD@Z)
GUIDlg.obj : error LNK2001: unresolved external symbol "void __cdecl player_init(struct player *)" (?player_init@@YAXPAUplayer@@@Z)
Debug/GUI.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

Thanks,
John
0
jsaxon2
Asked:
jsaxon2
1 Solution
 
ambienceCommented:
that can be because you are writing code in C++ (cpp) file, i think the console project that you are mentioning must be a .c file.

you can get around that problem by supressing name mangling for all the imported API. for e.g. if you are using the following prototype

void __cdecl player_finish(struct player *);

you should change that to

extern "C"
{
void __cdecl player_finish(struct player *);
};

and that should supress C++ name mangling. If the API comes from some header you can do something like

extern "C"
{
#include "header.h"
}

hope this helps
0
 
jsaxon2Author Commented:
extern "C"
{
#include "audio.h"
#include "player.h"
}

is exactly what I needed. Thanks a million.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now