Linker errors trying to use shapelib - c++

I am trying to include shapelib in an existing solution in MSVS 2010. However, I'm getting the following errors for each function call from shapelib:
error LNK2001: unresolved external symbol "extern "C" void __clrcall SHPDestroyObject(struct SHPObject *)" (?SHPDestroyObject##$$J0YMXPEAUSHPObject###Z) *.obj
So far what I've done was include the "shapefil.h" file in the *.cpp file (the same file name which gives the error for the *.obj). Also, I've added
$(SolutionDir)$(Platform)\$(Configuration)\shapelib.lib
to Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies. What should I do to fix this issue? I'm fairly new including external libraries so any help would be appreciated.

Related

I am getting Linker error LNK2019 in one of my modules in UE_4.26

I am trying to implement a module in UE_4.26 project where I am getting Linker Error like the following:
ChunkDemoGameInstance.cpp.obj: error LNK2019: unresolved external symbol "public: static int __cdecl
FChunkDownloaderDBWrapper::GetDatabase(class SQLiteDriver *)" (?GetDatabase#FChunkDownloaderDBWrapper##SAHPEAVSQLiteDriver###Z) referenced in function "public: void __cdecl
UChunkDemoGameInstance::OnPatchVersionResponse(class TSharedPtr<class IHttpRequest,1>,class TSharedPtr<class IHttpResponse,1>,bool)" (?OnPatchVersionResponse#UChunkDemoGameInstance##QEAAXV?$TSharedPtr#VIHttpRequest##$00##V?$TSharedPtr#VIHttpResponse##$00##_N#Z)
I was not getting this error earlier when I was compiling my code in VS2019 but now when I try to compile it gives the above error.
Can you update your post to include your Build.cs file for your module and your project? You need to make sure that you add your libraries to the module's build.cs file and in your project build.cs file you must add the module name as a module to be loaded by Unreal build tool during compile.
if (Target.Platform == UnrealTargetPlatform.Win32 ||
Target.Platform == UnrealTargetPlatform.Win64)
{
PublicSystemLibraries.Add("kernel32.lib");
}
Here's an example of adding the kernel32.lib file to be used during a build.

Unresolved external symbol with Catch library

I'm migrating some projects to use CMake build system. Now I'm adding project with some unit tests using the Catch library. It is header only library. The old Visual Studio project builds fine, but the new CMake project gives unresolved external symbol linker error. I have defined CATCH_CONFIG_MAIN in one of my source files. There are added all cpp files from other projects which are needed for the tests and all libraries on which other tested projects depend are linked. Despite this I have unresolved external symbol error only with generated from CMake project:
ChipCountTests.obj : error LNK2019: unresolved external symbol "public: __thiscall Catch::SourceLineInfo::SourceLineInfo(char const *,unsigned int)" (??0SourceLineInfo#Catch##QAE#PBDI#Z) referenced in function "void __cdecl `anonymous namespace'::`dynamic initializer for 'autoRegistrar1''(void)" (??__EautoRegistrar1#?A0xb4291ec5##YAXXZ)
1>FlyingChipRewardCalculatorUT.obj : error LNK2001: unresolved external symbol "public: __thiscall Catch::SourceLineInfo::SourceLineInfo(char const *,unsigned int)" (??0SourceLineInfo#Catch##QAE#PBDI#Z)
Obviously I'm missing to add some configuration from vcxproj to CMakeLists.txt but I'm currently can't figure it out.
In one of my files I have:
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
but I also using CMake macro for adding precompiled header to the project:
add_precompiled_header (${TARGET_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.h
${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.cpp)
This macro forcefully includes precompiled header in all files, but in it I have #include <catch.hpp> without #define CATCH_CONFIG_MAIN which is needed by all files except one.
I added option to the macro to pass list of files in which not to be included precompiled header and this resolves the issue.
It's a little bit hard to deduce a concrete problem from the context you provided, but here is an official Catch instruction for CMake integration.
In my experience using it with Visual Studio - integration went smoothly.
When I try to use Catch with the Precompiled Header option enabled in my test project, I end up with linker errors LNK2019.
I still use stdafx.h in my project and disable the Precompiled header option in order for the project to build.
Right-click project -> Configuration Properties -> C/C++->Precompiled Headers -> Precompiled Header -> Not Using Precompiled Headers.
I have the same error and I solved it by linking the target to Catch2WithMain
target_link_libraries( ${PROJECT_TEST} Catch2 Catch2WithMain)
set_property(TARGET ${PROJECT_TEST} PROPERTY CXX_STANDARD 14)
set_property(TARGET ${PROJECT_TEST} PROPERTY CXX_EXTENSIONS OFF)

LNK2019 Error Header is included but not linked?

I have some classes and headers that are external to my program that i wish to use. I am using MSVC2013 and have specified the location of these files in the "Additional include directories" entry in the project settings window. Intellisense recognises the paths and provides the appropriate syntax highlight and my program compiles fine except at the end it throws LNK2019 errors for any usage of these classes. Is there another place in linker settings I need to specify to link external files or am i missing something obvious here.
Error messages:
MainWindow.obj : error LNK2019: unresolved external symbol "public: __cdecl QPropertyEditorWidget::QPropertyEditorWidget(class QWidget *)" (??0QPropertyEditorWidget##QEAA#PEAVQWidget###Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
Header files typically provide the API and/or data structures for some other code (most likely a library). With the headers you know about the "other" code, but you don't actually "have it" in your program.
Specifying where to find the headers is only half of the problem. You also need to specify where to find the object files (or libraries), and which objects or libraries to link against.

error LNK2019 unresolved external symbol when trying to link dll

I know many people have asked about this error and trust me I've read ALL of them and followed all the steps! But I'm still getting the unresolved external symbol error.
I'm trying to use the dll of lp_solve (a linear programming package) in my c++ code in visual studio 2012.
The error message I'm getting is:
Error 80 error LNK2019: unresolved external symbol _make_lp#8 referenced in function "void __cdecl my_solve(BLAH BLAH)
The function make_lp() is from the lp_solve package and I'm calling it from my_solve() in my code. This error message pops up for each solver function I call. Seems the linker just couldn't find any of the implementation of these functions.
I've done the following
put #include "lp_lib.h" in my source code
put the .dll, .h and .lib files from the lp_solve package in the working directory and
added the path under Linker:General:Additional Library Directories.
added the lib under Linker:Input:Additional dependency
What's wrong?
Thanks for your help!
The problem I had was solved after realizing I downloaded the WIN64 package for lp_solve but my visual studio is using WIN32 as build platform (even though my machine is x86_64).
Using extern "C" may be helpful while including lp_lib.h in your .cpp as follows:
extern "C"
{
#include "lp_lib.h"
}
For more information, please check this link:
http://www.geeksforgeeks.org/extern-c-in-c/

Visual Studio doesn't compile, ATL error

I have uninstalled and reinstalled visual studio 2013 and always the same error on compiling:
Error 1837 error LNK2019: unresolved external symbol "int __cdecl ATL::_AtlInitializeCriticalSectionEx(struct _RTL_CRITICAL_SECTION *,unsigned long,unsigned long)" (?_AtlInitializeCriticalSectionEx#ATL##YAHPAU_RTL_CRITICAL_SECTION##KK#Z) referenced in function "public: long __thiscall ATL::CComCriticalSection::Init(void)" (?Init#CComCriticalSection#ATL##QAEJXZ)
AFAIK this function is membe of the atls.lib, Check your /verbose inker output if this library is included.
The command link /dump /symbols atls.lib Shows me that this Symbol is defined in that file and is included in my ATL projects.
it is very probably, that you are trying to compile sources that have included
their own atl header file implementation, just for compatibility satisfaction. In that case there in header files must be some pre-processor definition e.g. VBOX_COM_NO_ATL, which will tell not to use ATL at all.
to find the conflict - include atlcore.h in your source and see if it conflicts with some another atl header in your library/source code.