OpenGL/GLEW: Unresolved external _glewInit - c++

I cannot get GLEW to link correctly with my program.
I have the path correct in my project (I've triple checked), I have tried building from scratch, using the x86 libs (all 4 - the -s, -mxs, etc) AND the x64 libs.
I have tried using the #pragma directive instead of configuring my project in properties.
I am trying to get it as a static lib so no DLLs will be necessary.
I also have GLEW_STATIC defined, as the build instructions advise.
Error message:
OGLInit.obj : error LNK2019: unresolved external symbol _glewInit#0
referenced in function "bool __stdcall vexal::OGLStartup(void)"
(?OGLStartup#vexal##YG_NXZ)
I've even used dumpbin to check that initGlew is there. It is, and it is external.
I've also verified it's found the lib.
Searching
C:\Users\Jake\Documents\Vexal2\vexal\vc9_x86\lib\Debug\GLEW.lib:
I've run out of ideas here. Any help?

Yep. I rebuilt it using the glew_static project.
Just because you built that project doesn't mean you're linking to it.
C:\Users\Jake\Documents\Vexal2\vexal\vc9_x86\lib\Debug\GLEW.lib
That is not the static GLEW library. That is the import library for the DLL version of GLEW. The static GLEW library is called GLEW32s.lib. Link to that.

The problem was the calling convention. I changed the calling convention settings to __stdcall instead of __cdecl, changed _glfwTerminate_atexit( void ) to __cdecl in the GLFW code I had, and then built.
Fixed!

Related

Compiling C library in C++. Linking issue. MuPDF [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I tried multiple PDF lybrary and MUPDF is my last chance to build my own small PDF application. But here I also have problems. Before that I had problem with LNK4098: defaultlib 'MSVCRT', but I solved that to set for all MUPDF library /MDd version. Most errors is solved after that, but still I can't to solve this:
error LNK2001: unresolved external symbol "void __cdecl pdfapp_open(struct pdfapp_s *,char *,int)" (?pdfapp_open##YAXPEAUpdfapp_s##PEADH#Z)
//more 3 errors
As MuPDF written on C, I do this:
extern "C" {
#include <pdfapp.h>
#include <mupdf\fitz\context.h>
}
But I get this errors:
error LNK2001: unresolved external symbol pdfapp_open
//more 3 errors
There is only three functions what I use in my application. I checked libs and headers linking, I set my project Debug, x64, /MDd also but I get the same.
Honestly, I can't find this three functons in no one libs. I'm not a expert in programming but I know that functions strings should be finding in libs, doesn't? What does mean this errors in my case?
Either your linker is failing to find the import library for mupdf or you have a name mangling/decoration type issue.
Once you download and build mupdf, there should be an import library for you to link to. Are you linking to it? Look in your project linker settings under Linker >> Input >> Additional Dependencies. Have you added such an import?
If not, add it in. It shouldn't be hard to find. It is likely right next to the mupdf DLL that you downloaded (or built).
Assuming you have added it, your next step is to verify that you are properly finding it. Look at the build output. Are you getting a warning about it? No, change the Linker >> General >> Show Progress to "Display all progress messages" and build again. Is there a warning about the library or function?
Last possibility that I can think of is that the DLL is actually exporting its functions as C++ (i.e. with name decoration), not as extern "C". In that case and your extern "C" brackets don't belong there. Or perhaps vice versa (i.e. maybe you failed to use extern "C" in all places you #include it). I can see that your example uses it but is that all the places?
If you are building the mupdf.DLL be sure it is being built the same way and with the same calling convention as your client code.

Visual C++ linker can't resolve FFmpeg's external symbols

I'm making a C++ program and I want to use FFmpeg pre-built for x64, which is a C-compiled library.
I'm using this code in order to include its header:
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#pragma comment (lib,"G:/Documents/ffmpeg/lib/avcodec.lib")
#pragma comment (lib,"G:/Documents/ffmpeg/lib/avformat.lib")
}
I'm then calling the symbols like I would do for a normal function, for example with av_interleaved_write_frame(out->formatContext, &packet);
However, when I try to compile it with Visual Studio 2015's built-in C++ compiler, I get a lot of error like
Error LNK2019 unresolved external symbol _av_write_trailer referenced in function "void __cdecl closeArenaVideo(struct VideoOutput *)" (?closeArenaVideo##YAXPAUVideoOutput###Z) Sparta2 c:\Users\Théo\documents\visual studio 2015\Projects\Sparta2\Sparta2\video.obj
for basically any of the symbols I'm refering to.
I tried to import everything in Visual Studio, to compile with command-line, to manually put FFmpeg's libraries in the default libraries path, without success.
Thank you in advance!
A typical problem which is hard to understand from quoted linker errors is the problem of referencing wrong .lib files, esp Win32 platform libraries in x64 build and vice versa. The names might be correct, but the set is wrong and then linker takes the #pragma references but ignores the content.
You should make sure that your build platform matches the bitness of referenced library files. This answer has minimalistic project which does build well and you can compare code/references to what you use, and it also mentions bitness problem as well in the very bottom and comments to the answer.

Referencing static library in VC++

I am trying to statically link this library into my VS C++ project.First I compiled the source as a static lib.Linked it via VS Project properties.The .exe project works fine.Then I read this MS manual on how to compile the static lib into the executable and following the steps outlined there now if I am running the executable I am getting these errors:
Error 3 error LNK2019: unresolved external symbol __imp__glBlendFunc#8
referenced in function _text_buffer_render E:\Documents\visual studio
2012\Projects\XXXXEngine\FreeTypeTest\text-buffer.obj
Error 4 error LNK2019: unresolved external symbol __imp__glBindTexture#8
referenced in function _text_buffer_render E:\Documents\visual studio
2012\Projects\XXXXEngine\FreeTypeTest\text-buffer.obj
To me it seems like GLEW.lib errors.Does it mean I have to link also glew.lib statically as the freetype GL depends on it ?
Also, can I just use the lib with the executable without adding it to references, or it won't work in release build?I am asking it as I am quite confused with how the static linking should be done.I mean,now the executable works without adding the library to the project reference.Then why can't it be used just like this?
To me it seems like GLEW.lib errors
They are not, glBindTexture() is an OpenGL function. The MSDN library page is here. Scroll to the bottom, it shows you the .h file that declares it (you already that right since the compiler didn't complain) and the .lib you need to link.
Right-click your project, Properties, Linker, Input, Additional Dependencies setting. Add opengl32.lib. Or to use the upvoted answer's suggestion, you can inject the linker directive in your source code:
#include <gl\gl.h>
#pragma comment(lib, "opengl32.lib")
Have you tried to pragma mark your library?
Like so:
#pragma comment(lib, "any.lib");

linker says _IsolationAwareLoadLibrary is undefined - any ideas?

I added some boost stuff* to my code and the linking phase failed with:
error LNK2019: unresolved external symbol _IsolationAwareLoadLibraryA#4 referenced in function "void * __cdecl boost::interprocess::winapi::load_library(char const *)" (?load_library#winapi#interprocess#boost##YAPAXPBD#Z)
Can anyone help me figure this out? kernel32.lib is added in linker settings. I searched for _IsolationAwareLoadLibraryA and it doesn't seem to be present in Windows SDK 6.0A, which I'm using. The project is CLR if that matters.
*the boost stuff are two shared memory headers:
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
This functions are part of SDK 7.0A, and they should be inline (so there's no need to specify an .lib file). Try downloading and using a newer SDK, and make sure that ISOLATION_AWARE_ENABLED gets #defined, because this is what triggers the inclusion of those functions. I guess boost should define it by itself though.
It turned out the project I used had a "ISOLATION_AWARE_ENABLED=1" added to preprocessor definitions. Removing it fixed the linker error. Not sure whether this won't cause any other problems though. The disturbing fact is that I'm wasting lots of time just resolving various issues related to building my project with third-party C/C++ libraries.

How can I resolve "error LNK2019: unresolved external symbol"? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I've got this MFC application I'm working on that needs to have an embedded database. So I went hunting for a slick, fast "embeddable" database for it and stumbled accross SQLite.
I created a DB with it, and I created a static library project with Visual Studio 2008. the library project will be used in another main project.
In the library project, I created a class DBClass with a method AddFeedToDB(CFeed f). The library project uses the .lib file from codeproject (cppsqlite3.lib).
When compiling the static library, no error is detected, but when I try to use the library project file in the main project, I get these type of errors:
error LNK2019: unresolved external symbol "public:void __thiscall
CppSQLite3DB::close(void)" (?close#CppSQLite3DB##QAEXXZ
referenced in function "public: int __thiscall
CTalkingFeedsDB::AddFeedToDB(class CFeed,char const*)" (?
AddFeedToDB#CTalkingFeedsDB##QAEHVCFeed##PDB#Z
What am I missing?
I know it is already 2 years since this question... but i run in the same situation here. Added all the header files... added the lib directories.. and keep having this error.
So i added manually the lib to the Configuration Properties -> Linker -> Input -> Aditional Dependencies
and all works for me.
It happened to me more than once that I thought symbol XXX (i.e. ?close#CppSQLite3DB##QAEXXZ) was in the import lib, while the actual symbol was __impXXX (i.e. __imp?close#CppSQLite3DB##QAEXXZ).
The reason for the linker error is then to be found in the compilation step: the compiler will generate the ?close#CppSQLite3DB##QAEXXZ symbol to be imported, where it should generate __imp?close#CppSQLite3DB##QAEXXZ. This often means that the function declaration itself didn't have __declspec( dllimport ). Which may be caused by some preprocessor symbol not being defined. Or the __declspec not being there at all...
Don't know if it is your case, but the imp prefix may mean that you are compiling a x64 library in a Win32 project.
You either need to link the codeproject SQLite lib to your executable, or to include the sources files in your project directly. (Which one did you do ?)
I would follow these steps:
think about what library or .obj file you expect the symbol to be exported by.
check whether it actually does export that very symbol (check character-wise). Sometimes, it's the calling convention differs.
check if the library you expect to contain the symbol is known to the linker - first check for the 'additional libraries', then check if the library is actually found (I mostly do this by using filemon.exe from sysinternals, and look for link.exe to open the lib file. )
After thinking a while, you may find that your library project will not export the sought for function. That function is in the database lib. You should add that lib to your main project. It's no use adding it to your static lib project.
The compiler and linker will not link one library into another (unless one is a DLL). You need to specify both libraries (cppsqlite3.lib and your own static library) in your main project.