link static library in c++ visual studio - c++

can someone please help me to understand the process.
in c++ visual studio 2010
i have a visual studio solution (lets call it mysol)
i have a project built as a static library (let's call it staticprj)
staticprj needs to use a library from outside (lets call it ext.lib)
in the body of the source code of staticprj i include outside library header file with
# include extlib.h and make calls to some of its functions (let call them extfunctions())
i also include the the path to the header files location of the ext.lib.
the staticprj compiles okay without errors
the mysol also has another project which is a dynamic library (dynprj) and which depends on the staticprj.
also in the source files of the dynprj uses functions from outside library.
i have included #include extlib.h in the source code of dynprj.
i have included the path of the header files
i have attached extlib.h directly to the dynprj
i have also added ext.lib to the linker input (along with the path where the ext.lib resides).
i still get a lnk2001 error stating that extfunctions() where not found.
the whole structure (the mysol solution) compiles okay if i do not use ext.lib at all.
my question is how does the linking process works and what can i do to correct this linking error.
(note that without the presence of ext.lib my linking of the staticprj and dynprj is fine. my compilation works okay and my code works. i only get the linking error when i try to link another ext.lib to staticprj and dynprj and use functions from ext.lib)
thanks in advance.

I'm not quite sure it will work, but try putting the .dll inside your "mysol" debug folder. I had a similar problem couple of weeks ago when I had library compiled as .dll. I just placed that .dll within my debug folder and worked lovely.

Related

ImGui, SDL2 & code block, struggling to setup

since there is no real tutorial on how to setup ImGui & SDL2, I came here to find answers.
I just have to paste ImGui file into my include folder to setup it right ? At least, it is what the ImGui readme file says.
When i try this :
ImGui::Begin("test");
I have this error :
undefined reference to `ImGui::Begin(char const*, bool*, int)
Code block do autofill me with ImGui functions when I start to write 'i'. Also when I do #include other files (ImGui_draw, etc. ...), I got only redefinition problems.
=> That's why my question sis lighty different from the already answered following question :
What is an undefined reference/unresolved external symbol error and how do I fix it?
So please do not close this question. I'm looking for a solution from 2 day now and a question here is my only solution left. I will have to give up on ImGui if this question is closed.. I'm truly clueless.
Could this error be due to a conflict with SDL2's opengl ? But in this case, shouldn't just the program crash instead ?
EDIT : Now this error is solved(I used to work with an IDE who include itself the files in my include folder, I didn't knew code block didn't), I have my program launching but nothing related to ImGui happens (as expected, I didn't figured out yet how to mix SDL2 & ImGui) and another error happens now when I quit my SDL2 window :
The program crashes and display the following in the console :
Assertion failed: g.Initialized, file C:\(...)\imgui.cpp, line 3882
Some random testes: If I use ImGui before my main loop it crashes there. Same inside the loop.
I just have to paste ImGui file into my include folder to setup it right ?
No. The header files are needed for your app to see what symbols are out there for valid compilation. But during linking, those symbols actually need to be there, and adding a single header file is not going to add them. You need to bring all the source files (cpp files and probably their corresponding header files) into your app and compile it all together.
Building a C++ app has two main stages: compilation and linking. Your header path has all the information for the compilation stage, but not for linking. Only actual source files (which are not header files) can contain the symbols needed to define what is declared in your headers. If you don't add those too, then your symbols are not defined, which explains your error.
Code block do autofill me with ImGui functions when I start to write
'i'.
That's because you included the header file, which is one part of the process.
I got only redefinition problems.
And just in case you are doing this, don't use #include with any .cpp files, only header files. If you #include cpp files in more than one place, you will definitely get multiple definition errors, as you indicated.
Quoting from imgui's README:
ImGui is self-contained within a few files that you can easily copy
and compile into your application/engine:
imgui.cpp
imgui.h
imgui_demo.cpp
imgui_draw.cpp
imgui_internal.h
imconfig.h (empty by default, user-editable)
stb_rect_pack.h
stb_textedit.h
stb_truetype.h
So you don't only need the imgui.h header, you need all of these file, taking care of compiling and linking the cpp files into your executable.

How to build the Poco C++ libraries

I'm trying to build the Poco C++ libraries manually on Android, iOS, and windows. After much effort I got them to build on Android, but I'm struggling a bit on Windows.
I've had to manually edit several files already to resolve undefined symbols -- specifically File & Path weren't #included properly by *_WIN32U.cpp versions.
I'm down to what APPEARS to be my last compiler issue for "Foundation". It's this line in Process_WIN32U.cpp:
envChars = getEnvironmentVariablesBuffer(env);
The compiler error generated is:
"getEnvironmentVariablesBuffer identifier not found"
The declaration of "getEnvironmentVariablesBuffer" is in Process.cpp but it's not a member of the root class, there are no EXTERN references anywhere, and no header file contains the function declaration.
So how the heck is "Process_WIN32U.cpp" supposed to be able to see that function?
Thanks!
So how the heck is "Process_WIN32U.cpp" supposed to be able to see that function?
ProcessWIN32U.cpp (i.e. ProcessImpl class) is able to see that function because ProcessWIN32U.cpp is included from Process.cpp and it was not designed or meant to be used standalone - it is excluded from build in POCO Visual Studio solutions.
In order to get ProcessWIN32U.cpp to be included by Process.cpp, one must manually /D_WIN32 which is not defined by Visual Studio (it defines WIN32).

Unresolved external symbol when linking to third party libraries from UE4

EDIT:
Updated post to avoid linking to third party sites and to collect all required information here.
Any information is appreciated. If you need more info, please inform me and I will edit the post with the new details.
Here is some useful information to start with.
Errors.
Source code.
I am trying to use a third party SDK consisting of one lib file and essentially one header file. I manage to get the intellisense to work, but I get linker errors even though I have modified my project's build.cs file to add the library path.
public OculusTest(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
// Add static libs
PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "RPLidar/Libraries", "rplidar_driver.lib"));
// Add a path with the .h that has the function definitions
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "RPLidar", "Includes"));
}
I also checked if I was missing something, but in a standalone C++ project I use the same files and only the same files and it does work. The files in question are
RPLidar.h and rplidar_driver.lib
As such I assume the error is in me failing to tell the Unreal compiler where to find the lib file.
Thank you in advance for all information regarding this way too stubborn error.
I finally found my error.
After checking that the same version of VSC++ was used to compile both programs and that I checked that it was in the correct configuration I changed one extra thing that made it all work out.
Instead of compiling to a multi threaded LIB file, I compiled the code as a DLL file.
I did it by opening the LIB project properties and going to C/C++ -> Code Generation -> Runtime Library and setting it to Multithreaded DLL (/MD).
Under General I set the configuration type to be a static library (.lib).

c++ boost library Entry point could not be located

I have a c++ Lib project StoreLib, and I have UnitTest Project where I wrote a unit test to test a functionality of class in StoreLib. StoreLibuses bunch of external dlls
My boostTest project compiles and when I run the exe, it complained about missing bunch of dlls, I pasted all of them in my bin folder. Then get this weird error
Store.UnitTests.exe - Entry Point Not Found.
The procedure entry point could not be located in the dynamic link library C:\UnitTest\UnitTests.exe.
First I am unable to understand why is it treating an exe file (UnitTest.exe) as a dynamic link library ? if I write a simple test i.e. Boost_Check(6==6) with out referring to any header file in my StoreLib it works just fine, though moment I refer to any header file from StoreLib it gives above mentioned error.
Any clue what I am doing wrong ? any help would be appreciated
it turned out that the one the external dll included was old, perhaps it was not finding proer entry point

C++ #include external function issue

I'm a real beginner and I'm programming in C++ using Visual Studio.
I've a simple cpp code that recalls some functions written in a .c and .h file. I included that file by means of #include directive and the IDE "sees" the function.
When I compile, I get this
Error 7 error LNK2019: unresolved external symbol _IMUsendAccelToFIFO referenced in function _main D:\Cprojects\Pencil\Pencil\Pencil.obj Pencil
What am I missing here?
Thank you all!
It is a linker error, not a compiler error. The compiler is happy, it saw the declaration of function in the .h file. The linker isn't, it cannot find the definition of the function.
Add the .c file to your project.
If you get an error in Visual Studio you can actually google for the error code and you will get pretty extensive information for that. In this case, googling LNK2019 gives this MSDN page as first hit, which also provides some examples on how you get the error.
Your vendor should have provided some .lib files for you (usually found in a folder named lib?). Make sure that these are added in the project via:
Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies
You could also see if there is any "get started" information for you from your vendor, which explains which dependencies you have to include in your project.
If you feel unsure of what a compiler and what a linker does, pick up a book that explains it, or browse some free alternatives.
Are you using ghettopilot? that's the only reference I can find on the web to the function you're missing. If you are, then you need to include the .lib file for that library in your link options.
Visual Studio will compile .c files as C and .cpp files as C++ by default, and this can cause trouble because if you want to call functions defined in a .c file from a .cpp file, then you must wrap the header in extern "C" { }, as the compiler will expect all functions not declared extern "C" to be from C++. This is because of an implementation detail called name mangling. Alternatively, you could force all files to be compiled as C or as C++ in the project settings.
Solved! Thank you very much!
The libraries I was using needed to be built. I tried but I couldn't build them as I used to get "heap space" error!
I installed Visual Studio 2005 (with which the code was produced by the vendor) and it worked at first attempt! There are probably some back-compatibility issues..