RLib icon indicating copy to clipboard operation
RLib copied to clipboard

LNK1120 on compile

Open ghost opened this issue 7 years ago • 11 comments

Hi I trying to use RLib in vs2015 , The Rlib compile successfully but when wanna to use it(.lib) in a project i always got LNK1120 and LNK2019 Errors , It says can't resolve external symbols, Even for the following sample!

#include "RLib_Import.h"

int main()
{
    String rlibString;

    return 0;
}
Error	LNK1120	2 unresolved externals	Project1	C:\Users\ccc\Downloads\Compressed\RLib-master\Debug\Project1.exe	1
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __thiscall System::String::String(void)" (__imp_??0String@System@@QAE@XZ) referenced in function _main	Project1	C:\Users\ccc\Downloads\Compressed\RLib-master\Project1\Source.obj	1
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __thiscall System::String::~String(void)" (__imp_??1String@System@@QAE@XZ) referenced in function _main	Project1	C:\Users\ccc\Downloads\Compressed\RLib-master\Project1\Source.obj	1

ghost avatar Jul 24 '17 05:07 ghost

Hi, m0ax4vin, you can just include RLib_LibImport.h instead of RLib_Import.h, or add RLIB_LIB to preprocessor definitions.

Rprop avatar Jul 24 '17 05:07 Rprop

I do that too but the same result:

#include "RLib_LibImport.h"

using namespace System::Ini;

int main()
{
    IniFile ini;
    ini.Items.Add(new IniComment()); // empty comment
    ini.Items.Add(new IniComment(_R(" This File has been generated by RLib")));
    ini.Items.Add(new IniComment(_R(" Copyright (c) 2016 rrrfff, [email protected]")));

    ini["Section"]["Key"] = _R("Value");
    ini.SaveFile(_T("Config.ini"), UTF8Encoding);

    return 0;
}
Severity	Code	Description	Project	File	Line
Error	LNK2019	unresolved external symbol "public: class System::String __thiscall System::String::Trim(char)const " (?Trim@String@System@@QBE?AV12@D@Z) referenced in function "public: __thiscall System::Ini::IniKey::IniKey(class System::String const &,class System::String const &)" (??0IniKey@Ini@System@@QAE@ABVString@2@0@Z)	Project1	C:\Users\cccc\Downloads\Compressed\RLib-master\Project1\Source.obj	1
Error	LNK1120	4 unresolved externals	Project1	C:\Users\cccc\Downloads\Compressed\RLib-master\Debug\Project1.exe	1
Error	LNK1104	cannot open file 'RLib_x86d.lib'	IniReader	C:\Users\cccc\Downloads\Compressed\RLib-master\Examples\IniReader\LINK	1
Error (active)		expected a ')'	Project1	c:\Users\cccc\Downloads\Compressed\RLib-master\RLib\RLib_Import.h	140
Error	LNK2019	unresolved external symbol "public: static void * __cdecl System::AppBase::Allocate(int,char const *,char const *)" (?Allocate@AppBase@System@@SAPAXHPBD0@Z) referenced in function "public: static void * __cdecl System::Ini::IniComment::operator new(unsigned int)" (??2IniComment@Ini@System@@SAPAXI@Z)	Project1	C:\Users\cccc\Downloads\Compressed\RLib-master\Project1\Source.obj	1
Error	LNK2019	unresolved external symbol "public: static void * __cdecl System::IO::IAllocator::allocateMemory(int,char const *,char const *)" (?allocateMemory@IAllocator@IO@System@@SAPAXHPBD0@Z) referenced in function "public: void __thiscall System::Collections::Generic::List<class System::Ini::IniElement *,class System::Collections::Generic::IDisposable<class System::Ini::IniElement *>,class System::IO::IAllocator>::InitStorage(int)" (?InitStorage@?$List@PAVIniElement@Ini@System@@V?$IDisposable@PAVIniElement@Ini@System@@@Generic@Collections@3@VIAllocator@IO@3@@Generic@Collections@System@@QAEXH@Z)	Project1	C:\Users\cccc\Downloads\Compressed\RLib-master\Project1\Source.obj	1
Error	LNK2019	unresolved external symbol "void __cdecl __rlib_alert(char const *,char const *,char const *,char const *)" (?__rlib_alert@@YAXPBD000@Z) referenced in function "public: struct System::Collections::Generic::List<class System::Ini::IniElement *,class System::Collections::Generic::IDisposable<class System::Ini::IniElement *>,class System::IO::IAllocator>::ListNode * __thiscall System::Collections::Generic::List<class System::Ini::IniElement *,class System::Collections::Generic::IDisposable<class System::Ini::IniElement *>,class System::IO::IAllocator>::AddLast<class System::Ini::IniComment *>(class System::Ini::IniComment * &&)" (??$AddLast@PAVIniComment@Ini@System@@@?$List@PAVIniElement@Ini@System@@V?$IDisposable@PAVIniElement@Ini@System@@@Generic@Collections@3@VIAllocator@IO@3@@Generic@Collections@System@@QAEPAUListNode@0123@$$QAPAVIniComment@Ini@3@@Z)	Project1	C:\Users\cccc\Downloads\Compressed\RLib-master\Project1\Source.obj	1

ghost avatar Jul 24 '17 07:07 ghost

it seems that library directories was not properly set up

Rprop avatar Jul 24 '17 07:07 Rprop

No i set the directory now compile this simple code but any interact with String or other classes will cause same problem :|

#include "RLib_LibImport.h"
int main()
{
    String rlibString = "hello";
   
    return 0;
}

Please if it's possible give me an example project with .sln project file, may i set up something in wrong way. Thanks.

ghost avatar Jul 24 '17 07:07 ghost

you can use this wizard tool to help you create project, https://github.com/rrrfff/RLib/tree/master/Wizard, and its source code can be found here https://github.com/rrrfff/RLib/tree/master/Templates/Wizard

example projects are provided at https://github.com/rrrfff/RLib/tree/master/Examples, you can use those .vcxproj directly

Rprop avatar Jul 24 '17 07:07 Rprop

Thanks a lot.

Create a project .. but now it looking for ntdllp_x86.lib file, where is it ? ntdll_x64.lib and ntdll_x86.lib are in RLib-master\RLib\native\native.zip i extracted theme but don't found ntdllp_x86.lib

Severity Code Description Project File Line Error LNK1104 cannot open file 'ntdllp_x86.lib' test C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\LINK 1

ghost avatar Jul 24 '17 08:07 ghost

sorry, i will upload them soon

now you can find them here https://github.com/rrrfff/RLib/tree/master/RLib/native

Rprop avatar Jul 24 '17 08:07 Rprop

Thanks again i got new files

I compile Rlib in all possible forms (dll, lib, debug,release ....) in Bin folder. Then Create a project put compiled files on $(OutDir); of created template project Then try to compile default code:

#include <RLib_Import.h>
#include <RLib_NoCRT.h>
void main()
{
	String example = _R("RLib Example");`
}

In this case i got error Error LNK1104 cannot open file 'RLib_x86d.lib' Because "RLIB_LIB " isn't defined (It define when include "RLib_LibImport.h") and try to link RLib_x86d.lib instead of RLib_x86dl.lib

#  ifdef RLIB_LIB
	RLIB_IMPORT_LIB("RLib_" RLIB_PLATFORM "dl")
#  else
	RLIB_IMPORT_LIB("RLib_" RLIB_PLATFORM "d")
#  endif // RLIB_LIB

When include "RLib_LibImport.h" got this errors

Severity	Code	Description	Project	File	Line
Error	LNK2019	unresolved external symbol _rand referenced in function "public: static int __cdecl System::Random::NextInt(void)" (?NextInt@Random@System@@SAHXZ)	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_Random.obj)	1
Error	LNK1120	13 unresolved externals	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\bin\test_x86d.exe	1
Error	LNK2001	unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_BufferedStream.obj)	1
Error	LNK2001	unresolved external symbol "void __cdecl operator delete(void *,unsigned int)" (??3@YAXPAXI@Z)	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_MemoryPool.obj)	1
Error	LNK2001	unresolved external symbol "void __cdecl operator delete(void *,unsigned int)" (??3@YAXPAXI@Z)	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_Text.obj)	1
Error	LNK2019	unresolved external symbol "void __cdecl operator delete(void *,unsigned int)" (??3@YAXPAXI@Z) referenced in function "public: void * __thiscall System::ManagedObject<class System::IO::BufferedStream>::`scalar deleting destructor'(unsigned int)" (??_G?$ManagedObject@VBufferedStream@IO@System@@@System@@QAEPAXI@Z)	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_GlobalizeString.obj)	1
Error	LNK2019	unresolved external symbol _atexit referenced in function "void __cdecl `dynamic initializer for 'RLib_GlobalBasePool''(void)" (??__ERLib_GlobalBasePool@@YAXXZ)	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib.obj)	1
Error	LNK2019	unresolved external symbol _srand referenced in function "public: static void __cdecl System::Random::Srand(unsigned int)" (?Srand@Random@System@@SAXI@Z)	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_Random.obj)	1
Error	LNK2001	unresolved external symbol __purecall	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_BufferedStream.obj)	1
Error	LNK2001	unresolved external symbol ___dynamic_value_reloc_table	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\ntdllp_x86.lib(loadcfg.obj)	1
Error	LNK2001	unresolved external symbol ___guard_iat_count	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\ntdllp_x86.lib(loadcfg.obj)	1
Error	LNK2001	unresolved external symbol ___guard_iat_table	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\ntdllp_x86.lib(loadcfg.obj)	1
Error	LNK2001	unresolved external symbol ___guard_longjmp_count	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\ntdllp_x86.lib(loadcfg.obj)	1
Error	LNK2001	unresolved external symbol ___guard_longjmp_table	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\ntdllp_x86.lib(loadcfg.obj)	1
Error	LNK2001	unresolved external symbol ___stdio_common_vsnwprintf_s	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_MemoryPool.obj)	1
Error	LNK2001	unresolved external symbol ___stdio_common_vsnwprintf_s	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_String.obj)	1
Error	LNK2019	unresolved external symbol ___stdio_common_vsnwprintf_s referenced in function __vsnwprintf_s_l	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_AppBase.obj)	1
Error	LNK2019	unresolved external symbol ___stdio_common_vswprintf referenced in function __vscwprintf_l	test	C:\Users\cccc\Downloads\Compressed\RLib-master\Wizard\test\RLib_x86dl.lib(RLib_String.obj)	1

ghost avatar Jul 24 '17 08:07 ghost

simply delete or comment out #include <RLib_NoCRT.h> will solve your problem, because RLib_NoCRT.h doesn't work if you use static libarary, it will disable the use of CRT

Rprop avatar Jul 24 '17 08:07 Rprop

Ohhh :-),it's fine.

A little mention, If use main() function got an error

int _tmain()
{
	String example = _R("RLib Example");
    return 0;
}
Severity	Code	Description	Project	File	Line
Error	LNK2019	unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

Replace main() by WinMain(...) Everything was ok

int __stdcall WinMain(__in HINSTANCE /*hInstance*/, __in_opt HINSTANCE /*hPrevInstance*/,
    __in LPSTR /*lpCmdLine*/, __in int /*nShowCmd*/)
{
	String example = _R("RLib Example");
    return 0;
}

Thanks for your great lib and great support. Greetings.

ghost avatar Jul 24 '17 08:07 ghost

Thanks, got it.

And the cause is that the project has Windows (/SUBSYSTEM:WINDOWS) specified rather than Console (/SUBSYSTEM:CONSOLE)

Rprop avatar Jul 24 '17 08:07 Rprop