Les erreurs LNK2001

DakM Messages postés 65 Date d'inscription jeudi 20 janvier 2005 Statut Membre Dernière intervention 25 juin 2010 - 31 mars 2005 à 18:17
cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 - 1 avril 2005 à 23:37
Avis aux amateurs d'erreurs LNK2001:

Si quelqu'un pourrais m'xpliquer
pourquoi quand japelle un fonction du fichier game.cpp à partir du
fichier main.cpp lorsque je compile le programme, les fonctions
appellées reviennent sous forment d'erreur lors de cette compilation

debug:


--------------------Configuration: aRPG - Win32 Debug--------------------

Compiling...

game.cpp

Linking...

LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "libc.lib" conflicts with use of other libs; use /NODEFAULTLIB:library

main.obj : error LNK2001: unresolved external symbol "bool __cdecl player_pwdok(char *,char *)" (?player_pwdok@@YA_NPAD0@Z)

main.obj : error LNK2001: unresolved external symbol "bool __cdecl player_exist(char * const)" (?player_exist@@YA_NQAD@Z)

main.obj : error LNK2001: unresolved external symbol "bool __cdecl player_add(char *,char *)" (?player_add@@YA_NPAD0@Z)

Debug/aRPG.exe : fatal error LNK1120: 3 unresolved externals

I'm a killing Master

6 réponses

DakM Messages postés 65 Date d'inscription jeudi 20 janvier 2005 Statut Membre Dernière intervention 25 juin 2010
31 mars 2005 à 19:27
le warning LNK4098 viens d'etre resolu, le reste j'y arrive toujours pas :/

I'm a killing Master
0
cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 9
31 mars 2005 à 19:51
a premiere vu c'est parce que tu ne lie pas les librairie correspondant aux fonctions que tu appelles
Bob...

"La chance accorde ses faveur aux esprits avertis..."
0
DakM Messages postés 65 Date d'inscription jeudi 20 janvier 2005 Statut Membre Dernière intervention 25 juin 2010
31 mars 2005 à 22:51
mais les fonctions que tu voient sont perso ya pas de lib :x

I'm a killing Master
0
cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 9
1 avril 2005 à 09:56
est-ce que tu as le prototype de tes fonctions dans un .h et est ce que tu l'as inclue dans le cpp ou tu utilises tes fonctions?
Bob...

"La chance accorde ses faveur aux esprits avertis..."
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
DakM Messages postés 65 Date d'inscription jeudi 20 janvier 2005 Statut Membre Dernière intervention 25 juin 2010
1 avril 2005 à 16:04
ouai japelle de main.cpp les fonctions qui sont dans game.cpp

dans main.cpp et game.cpp ya #include "game.h"

I'm a killing Master
0
cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 9
1 avril 2005 à 23:37
je ne sais pas si cela te sera d'une grande aide, mais j'ai trouver ca sur ton erreur:


[mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_function_inlining_problems.htm function inlining] yet defines the functions in a .CPP file rather than in the header file can cause LNK2001.


<LI>If you are using C++, make sure to use extern “C” when calling a C function from a C++ program. By using extern “C” you force the use of the C naming convention. Be aware of compiler switches like [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_.2f.tc.2c_2f.tp.htm /Tp] or [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_.2f.tc.2c_2f.tp.htm /Tc] that force a file to be compiled as a C (/Tc) or C++ (/Tp) file no matter what the filename extension, or you may get different function names than you expect.


<LI>Attempting to reference functions or data that don't have external linkage causes LNK2001. In C++, inline functions and const data have internal linkage unless explicitly specified as extern.


<LI>A [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_missing_function_body_or_variable.htm missing function body or variable] will cause LNK2001. Having just a function prototype or extern declaration will allow the compiler to continue without error, but the linker will not be able to resolve your call to an address or reference to a variable because there is no function code or variable space reserved.


<LI>[mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_name_decoration.htm Name decoration] incorporates the parameters of a function into the final decorated function name. Calling a function with parameter types that do not match those in the function declaration may cause LNK2001.


<LI>Incorrectly included prototypes will cause the compiler to expect a function body that is not provided. If you have both a class and non-class implementation of a function
F
, beware of C++ scope-resolution rules.


<LI>When using C++, make sure that you [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_missing_function_body_or_variable.htm include the implementation] of a specific function for a class and not just a prototype in the class definition.


<LI>Attempting to call a pure virtual function from the constructor or destructor of an abstract base class will cause LNK2001 since by definition a pure virtual function has no base class implementation.


<LI>Only global functions and variables are public.
[mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_the_symbol_is_not_public.htm Functions declared with the static modifier] by definition have file scope. Static variables have the same limitation. Trying to access any static variables from outside of the file in which they are declared can result in a compile error or LNK2001.


A variable declared within a function ([mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_automatic_.28.function_scope.29_.variables.htm a local variable]) can only be used within the scope of that function.


[mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_global_constants_in_c.2b2b.htm C++ global constants] have static linkage. This is different than C. If you try to use a global constant in C++ in multiple files you get error LNK2001. One alternative is to include the const initializations in a header file and include that header in your .CPP files when necessary, just as if it was a function prototype. Another alternative is to make the variable non-constant and use a constant reference when assessing it.

</LI>
Compiling and Linking Problems

<LI>The names of the Microsoft run-time and MFC libraries needed at link time are included in the object file module by the Microsoft compiler. If you use the /NOD ([mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_.2f.nodefaultlib.htm /NODEFAULTLIB]) option, these libraries will not be linked into the project unless you have explicitly included them. Using /NOD will cause error LNK2001 in this case.


<LI>If you are using Unicode and MFC, you will get an unresolved external on _WinMain@16 if you don’t create an entrypoint to wWinMainCRTStartup. Use the /ENTRY option or type this value in the Project Settings dialog box. (To find this option in the development environment, click Settings on the Project menu, then click the Link tab, and click Output in the Category box.) See [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_unicode_programming_summary.htm Unicode Programming Summary].

See the following Knowledge Base articles located in the Online Information System for more information. An easy way to reach an article is to copy a "Q" number above, open the Search dialog box from the Help menu and select the Query tab, then paste the number into the first text box and press ENTER.

<LI>Q125750 "PRB: Error LNK2001: '_WinMain@16': Unresolved External Symbol"


<LI>Q131204 "PRB: Wrong Project Selection Causes LNK2001 on _WinMain@16"


<LI>Q100639 "Unicode Support in the Microsoft Foundation Class Library" </LI>
<LI>Linking code compiled with /MT with the library LIBC.LIB causes LNK2001 on _beginthread, _beginthreadex, _endthread, and _endthreadex.


<LI>When compiling with /MD, a reference to "func" in your source becomes a reference "__imp__func" in the object since all the run-time is now held within a DLL. If you try to link with the static libraries LIBC.LIB or LIBCMT.LIB, you will get LNK2001 on __imp__func. If you try to link with MSVCxx.LIB when compiling without /MD you will not always get LNK2001, but you will likely have other problems.


<LI>Linking code compiled with an explicit or implicit /ML to the LIBCMT.LIB causes LNK2001 on _errno.


<LI>Linking with the release mode libraries when building a debug version of an application can cause LNK2001. Similarly, using an /Mxd option (/MLd, /MTd, or /MDd) and/or defining _DEBUG and then linking with the release libraries will give you potential unresolved externals (among other problems). Linking a release mode build with the debug libraries will also cause similar problems.


<LI>Mixing versions of Microsoft libraries and compiler products can be problematic. A new compiler version's libraries may contain new symbols that cannot be found in the libraries included with previous versions. Use [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_dumpbin_reference.htm DUMPBIN] to find out if a symbol is in a 32-bit object file or library.


<LI>There is currently no standard for [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_name_decoration.htm C++ naming] between compiler vendors or even between different versions of a compiler. Therefore linking object files compiled with other compilers may not produce the same naming scheme and thus cause error LNK2001.


<LI>[mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_function_inlining_problems.htm Mixing inline and non-inline compile options] on different modules can cause LNK2001. If a C++ library is created with function inlining turned on (/Ob1 or /Ob2) but the corresponding header file describing the functions has inlining turned off (no inline keyword), you will get this error. To prevent this problem, have the inline functions defined with inline in the header file you are going to include in other files.


<LI>If you are using the #pragma inline_depth compiler directive, make sure you have a [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_error_function_inlining_problems.htm value of 2 or greater set], and make sure you are using the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_.2f.ob.htm /Ob1] or [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_.2f.ob.htm /Ob2] compiler option.


<LI>Omitting the LINK option /NOENTRY when creating a resource-only DLL will cause LNK2001.


<LI>Using incorrect /SUBSYSTEM or /ENTRY settings can cause LNK2001. For example, if you write a character-based application (a console application) and specify /SUBSYSTEM:WINDOWS, you will get an unresolved external for WinMain. For more information on these options and entry points, see the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_.2f.subsystem.htm /SUBSYSTEM] and [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_.2f.entry.htm /ENTRY] linker options. </LI>
Export Problems

<LI>When you are porting an application from 16 to 32 bits, LNK2001 can occur. The current 32-bit module-definition (.DEF) file syntax requires that __cdecl, __stdcall, and __fastcall functions be listed in the EXPORTS section without underscores (undecorated). This differs from the 16-bit syntax, where they must be listed with underscores (decorated). For more information, see the description of the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/_core_exports.htm EXPORTS] section of module-definition files.


<LI>Any export listed in the .DEF file and not found will cause LNK2001. This could be because it does not exist, is spelled incorrectly, or uses decorated names (.DEF files do not take decorated names). </LI>
This error message is followed by fatal error [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\VC6intro\1033\vccore.chm::/html/lnk1120.htm LNK1120].
Bob...

"La chance accorde ses faveur aux esprits avertis..."
0
Rejoignez-nous