Tinyxml - Link errors when targeting x64 platform - c++

I'm using tinyxml library for parsing XML files in my project. When I try to target x64 platforms I get LINKER errors and here is one fo them:
Error 4 error LNK2001: unresolved external symbol "private: static
struct TiXmlString::Rep TiXmlString::nullrep_"
(?nullrep_#TiXmlString##0URep#1#A) ClassThatUsesTinyXML.obj
Update : I figured that the x64 version of tinyxml was not installed but when I tried to build the library for x64 platforms I got this error :
LNK1561: entry point must be defined

Instead of building tinyxml for x64 platforms and then adding tinyxml.h and tinystr.h to the project, I just added all the library files including the .cpp files and now I can target x64 platforms, the library is, in fact, being built when I build the whole project.

It does not look like tinyxml supports shared library builds out of the box.
Here are the steps that I followed to build a DLL from the tinyxml 2.6.2 sources:
Open the provided SLN file, tinyxml.sln, in MS Visual Studio Express 2012 for Windows Desktop. Elect to convert the old project files to the new format when prompted.
From "Solution Platforms", select "Configuration Manager..."
From "Active solution platform:" select "<New...>"
In "Type or select the new platform:" select "x64" if not already selected. Make sure to copy settings from the "Win32" configuration. Click OK. Click Close to exit the Configuration Manager.
Right click on the tinyxml project in Solution Explorer. Select "Properties".
For "Configuration:", select "All Configurations". Similarly, for "Platform:" select "All Platforms".
On the Configuration Properties → General page, change "Configuration Type" to "Dynamic Library (.dll)". Change "Target Extension" to ".dll". Click OK to exit the tinyxml Properties Pages dialog.
Select the "Release" configuration and "x64" platform.
Right click on the tinyxml project in Solution Explorer again and select "Rebuild".
Within tinyxml_2_6_2\tinyxml\x64\Release you will find tinyxml.dll, but no import library (tinyxml.lib). This is because no symbols are exported. See How do I build an import library (.lib) AND a DLL in Visual C++?
If you want to go the shared library route, you will need to export the desired symbols via the MSVC-specific __declspec(dllexport) modifier. See Symbol Visibility in Windows.

The errors occurs when you define TIXML_USE_STL for the compilation of the library, but not for the sources that link to the library. The end result is that the library is compiled with different code from the sources using the library.

Related

Matrix multiplication using cublasSgemm in C++ [duplicate]

I am trying to compile a cuda program which uses cusparse library. I am getting linking error:
kernel.cu.obj : error LNK2019: unresolved external symbol _cusparseSetMatIndexBase#8 referenced in function _main
And a lot of error of same kind related to cusparse library. I have included "cusparse_v2.h".
How do i link cusparse library in visual studio 2010 during compilation?
The general instructions for linking libraries is not specific to CUDA. So you may want to learn more about using MS VS. Anyway, the steps are like this:
Make sure you have opened the project that you want to work on.
Select View...Property Pages (from the menu) A new dialog box will open up.
On the left hand side of this dialog box, select Linker to open up it's sub-menu
Under linker, select Input
Now, on the pane on the right, observe the first item which is "Additional Dependencies". I believe cudart.lib should already be present there.
Click to the right of cudart.lib You can now type in new libraries to be added. Type a space (to separate from cudart.lib) and type cusparse.lib
Now click "Apply" in the lower right corner of the dialog box.
That should be all that's needed, if your project/solution file is already set up using a cuda template. If cudart.lib is not present, or your project/solution files do not already comprehend cuda, that is a separate issue. In that case I would recommend starting over, by cloning a project from the Samples, and building your project using that as a starting point. It will then pick up all the proper directories to search as well as the cuda build rules. Since all the main cuda libraries (cudart, cublas, cufft, cusparse, etc.) are all in the same location, the same search path should pick any of them up as needed.
If you wanted to link another library, such as cublas.lib, for example, you could follow a similar sequence, replacing cusparse.lib above with cublas.lib
Note that with newer versions of CUDA (e.g. CUDA 7.5) it will be necessary to build a 64-bit project only (follow the above steps when modifying the x64 project properties.) CUDA 7.5 and beyond are dropping support for 32-bit projects.
I fixed it by following steps:
Add cuda path:
Go: "Configuration Properties->Linker->General->Additional Libary Directories" and add $(CudaToolkitLibDir) to the list.
Add cuda realtime library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cudart.lib to the list.
Add cublas library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cublas.lib to the list.
Changing platform to x64:
Go: "Configuration Properties->Platform" and set it to x64.
Run cmd.exe as administrator.
Type in and run the following two lines of command:
netsh winsock reset catalog
netsh int ip reset reset.log hit
It may say that a reboot is required, but actually that is not necessary.
Try to debug your application again, the problem should be solved.

VS2019 Using a static library with iOS project

Trying to port an example project for a product that uses a static library for iOS 13.2. The library is an "SDK" with the headers and .a and built singularly for "ARM64 Release" for the iPad. The original project, written for iOS 8.1 with VS2017, simply used -llibSomething.a in the "Additional Options" field and that worked. When doing the same in VS2019, the mac reports back that the linker option is ignored and fails to include it in the command that actually builds the application resulting in missing symbols. For the C++ application settings, there are no express linker options in the property page for the project unless I'm missing something--I'm not a big visual studio or iOS person. I know the path to the SDK is correct, the project finds the headers and compiles the sources without any undefined symbols, it just won't seem to link in the library. The biggest issue is that this all has to be done with whatever Visual Studio has to offer. Am I missing a dialog where this reference is supposed to go or is there something in the project.pbxproj that I'm supposed to be modifying?
Wound up answering my own question:
Unload the project
Edit the project.pbxproj
In the XCBuildConfiguration area for your configuration, add an entry for OTHER_LDFLAGS = "-lSomething ";
The list is just space separated, same as on the command line

cuBLAS examples, external symbol unresolved, VS2015 [duplicate]

I am trying to compile a cuda program which uses cusparse library. I am getting linking error:
kernel.cu.obj : error LNK2019: unresolved external symbol _cusparseSetMatIndexBase#8 referenced in function _main
And a lot of error of same kind related to cusparse library. I have included "cusparse_v2.h".
How do i link cusparse library in visual studio 2010 during compilation?
The general instructions for linking libraries is not specific to CUDA. So you may want to learn more about using MS VS. Anyway, the steps are like this:
Make sure you have opened the project that you want to work on.
Select View...Property Pages (from the menu) A new dialog box will open up.
On the left hand side of this dialog box, select Linker to open up it's sub-menu
Under linker, select Input
Now, on the pane on the right, observe the first item which is "Additional Dependencies". I believe cudart.lib should already be present there.
Click to the right of cudart.lib You can now type in new libraries to be added. Type a space (to separate from cudart.lib) and type cusparse.lib
Now click "Apply" in the lower right corner of the dialog box.
That should be all that's needed, if your project/solution file is already set up using a cuda template. If cudart.lib is not present, or your project/solution files do not already comprehend cuda, that is a separate issue. In that case I would recommend starting over, by cloning a project from the Samples, and building your project using that as a starting point. It will then pick up all the proper directories to search as well as the cuda build rules. Since all the main cuda libraries (cudart, cublas, cufft, cusparse, etc.) are all in the same location, the same search path should pick any of them up as needed.
If you wanted to link another library, such as cublas.lib, for example, you could follow a similar sequence, replacing cusparse.lib above with cublas.lib
Note that with newer versions of CUDA (e.g. CUDA 7.5) it will be necessary to build a 64-bit project only (follow the above steps when modifying the x64 project properties.) CUDA 7.5 and beyond are dropping support for 32-bit projects.
I fixed it by following steps:
Add cuda path:
Go: "Configuration Properties->Linker->General->Additional Libary Directories" and add $(CudaToolkitLibDir) to the list.
Add cuda realtime library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cudart.lib to the list.
Add cublas library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cublas.lib to the list.
Changing platform to x64:
Go: "Configuration Properties->Platform" and set it to x64.
Run cmd.exe as administrator.
Type in and run the following two lines of command:
netsh winsock reset catalog
netsh int ip reset reset.log hit
It may say that a reboot is required, but actually that is not necessary.
Try to debug your application again, the problem should be solved.

Error Linking CUDA 8.0 in VS2015 using OpenCV 3.2 [duplicate]

I am trying to compile a cuda program which uses cusparse library. I am getting linking error:
kernel.cu.obj : error LNK2019: unresolved external symbol _cusparseSetMatIndexBase#8 referenced in function _main
And a lot of error of same kind related to cusparse library. I have included "cusparse_v2.h".
How do i link cusparse library in visual studio 2010 during compilation?
The general instructions for linking libraries is not specific to CUDA. So you may want to learn more about using MS VS. Anyway, the steps are like this:
Make sure you have opened the project that you want to work on.
Select View...Property Pages (from the menu) A new dialog box will open up.
On the left hand side of this dialog box, select Linker to open up it's sub-menu
Under linker, select Input
Now, on the pane on the right, observe the first item which is "Additional Dependencies". I believe cudart.lib should already be present there.
Click to the right of cudart.lib You can now type in new libraries to be added. Type a space (to separate from cudart.lib) and type cusparse.lib
Now click "Apply" in the lower right corner of the dialog box.
That should be all that's needed, if your project/solution file is already set up using a cuda template. If cudart.lib is not present, or your project/solution files do not already comprehend cuda, that is a separate issue. In that case I would recommend starting over, by cloning a project from the Samples, and building your project using that as a starting point. It will then pick up all the proper directories to search as well as the cuda build rules. Since all the main cuda libraries (cudart, cublas, cufft, cusparse, etc.) are all in the same location, the same search path should pick any of them up as needed.
If you wanted to link another library, such as cublas.lib, for example, you could follow a similar sequence, replacing cusparse.lib above with cublas.lib
Note that with newer versions of CUDA (e.g. CUDA 7.5) it will be necessary to build a 64-bit project only (follow the above steps when modifying the x64 project properties.) CUDA 7.5 and beyond are dropping support for 32-bit projects.
I fixed it by following steps:
Add cuda path:
Go: "Configuration Properties->Linker->General->Additional Libary Directories" and add $(CudaToolkitLibDir) to the list.
Add cuda realtime library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cudart.lib to the list.
Add cublas library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cublas.lib to the list.
Changing platform to x64:
Go: "Configuration Properties->Platform" and set it to x64.
Run cmd.exe as administrator.
Type in and run the following two lines of command:
netsh winsock reset catalog
netsh int ip reset reset.log hit
It may say that a reboot is required, but actually that is not necessary.
Try to debug your application again, the problem should be solved.

error LNK1181: cannot open input file 'kernel32.lib'

I have a project on VS 2012. latest SDK is installed on the WIN 8 x64 computer, the project is targeting WIn32.
I have a clean build in Debug, but when I go to release I get the 1181 LNK error - cannot open input file kernel32.lib.
I have the file on the computer in several location, and in the VC directories there is $(WindowsSdkDir_71A)lib and $(WindowsSdkDir)\lib.
Using process monitor I've tried to rebuild and see where devenv.exe is looking for the file
** UPDATE:
In debug it looks in the right place.
in release it doesn't look for the sdk,
but I see this:
Y:\MyProjectFofler\$(LibraryPath)\kernel32.lib PATH NOT FOUND
and also several successful reads from the win8.0 sdk (which should be ok, but the result is the same, and I need it to read from the V7.1A SDK folder...)
What can it be and what might be the solution for this error ?
Thanks.
I ran into this using Visual Studio 2017. I was trying to get the Visual Studio project configurations to reference the external library .lib files I wanted. I managed to trigger this error when I removed any reference to the system libraries. I later figured out this can be corrected by including one of their macro values (though you can specify an absolute direct path, but that's probably not the best coding convention and prone to brittleness).
On the Visual Studio project, right-Clicking on the project item in the Solution explorer panel (not the Solution itself, which is the topmost item), then select Properties. From there do the following:
VC++ Directories --> Library Directories : $(ProjectDir)lib; $(LibraryPath)
Note the $(LibraryPath) value will include extra values such as inherited from parents, and from what I can tell this is a verbose option. My folder project contained a folder called 'lib' which is why I had the first value there before the semicolon.
There are other common options I have used to specify the Library Directories value:
$(VC_LibraryPath_x86)
$(WindowsSDK_LibraryPath_x86)
$(NETFXKitsDir)Lib\um\x86
If you look at the section VC++ Directories --> Library Directories, you can click on the entry line and select 'Edit', then you can watch live previews of what Macros values will be evaluated and resolved to. If you need additional or more specialized values, click on the Macros button to look for more options.
Link to image of Visual Studio 2017 Library Directories configuration