Trouble Linking libsndfile in Visual Studio 2010 Express - dll

I've been attempting to use libsndfile (it is the windows 64 bit version) for the first time, and have encountered a problem while trying to link it. Whenever I try to compile the program, I get this error:
error LNK2019: unresolved external symbol _sf_close referenced in function _main
This is the process I've done so far to attempt to link it to the program.
In project properties I have gone to Config. Prop.-> VC++ Directories, and added the path to the header files to the include directories tab, and the path to the .lib files to library directories tab.
In C/C++-> General-> Additional Include Directories, I have added the path to the header files.
In Linker->Input->Additional Dependencies I have added the path to the .lib file, which for me is C:\Program Files\Mega-Nerd\libsndfile\lib\libsndfile-1.lib
I've added #include "sndfile.h" to the .cpp file but for some reason it doesn't seem to have access to the functions in the dll. I don't really know a lot about linking, and what I've done is just what I've been able to piece together from scouring the internet, so I'm not really sure on what I'm doing wrong or right. Any help is greatly appreciated.

You are probably compiling a 32 bit project in Visual Studio, and trying to link it with a 64 bit library. It won't work... download the 32 bit version of the windows binary of libsndfile and use it to link to your executable. Another option is to create a 64 bit project, but I think the first option is (slightly) easier.

Related

issue when building module using cmake

i am trying to build box2D using cmake. When i click configure (and selecting my version of visual studio) cmake starts working but it finnishes with the error message:
You have called ADD_LIBRARY for library glfw without any source files.
This typically indicates a problem with your CMakeLists.txt file
Configuring done
What is the issue and how can i solve it? Where is the CMakeLists.txt located and how can i edit it to build without errors?
It is probably an error in this library. Try another version or post a bug.
It means that according to this file, a library should be created without source files (an empty library), which is probably bug.
CMakeLists.txt is located in every cmake source directory, make sure you're choosing the right directory.

Why would an application not find the DLL “boost_thread-vc100-mt-1_46_1.dll”?

Question: why would an application not find the DLL “boost_thread-vc100-mt-1_46_1.dll” when the DLL is in fact properly installed, and other applications use the DLL successfully?
Problem: when starting an instance of my application, the following error message appears:
“The program can’t start because boost_thread-vc100-mt-1_46_1.dll is missing from your computer. Try reinstalling the program to fix this problem.”
Several reasons why this message confuses me:
The dll is present in C:\Program Files(x86)\boost\boost_1_46_1\lib
Another project with similar settings runs properly and does create
boost::thread objects successfully
When I remove the code that creates boost::thread objects from my application, the error
message does not appear.
Additional details:
I am developing a C++/CLI application using MS VS 2010 with CLR enabled.
I am using the Boost Thread library (version 1.46.1).
Following the advice on posts about using Boost Thread and C++/CLI, I added the following code to one of my header files:
#if defined(_MANAGED)
#define BOOST_USE_WINDOWS_H
#endif
#define BOOST_THREAD_USE_DLL
#include "boost/thread.hpp"
namespace boost {
struct thread::dummy {};
}
#pragma warning(push)
#pragma warning(disable:4793)
#include "boost/thread/mutex.hpp"
#pragma warning(pop)
#include "boost/thread/locks.hpp"
I appreciate any advice you may have. Thank you.
Being in C:\Program Files(x86)\boost\boost_1_46_1\lib doesn't help much.
It needs to be in the DLL search path.
Other applications using boost probably have a local copy of the DLL alongside the main executable.
You need to add the location of the boost libs to the linker search path.
Right click on the C++ project that is showing the linker error, select Properties. Go to Linker -> General then in the right hand panel you see Additional Library Directories. Put in the path to the folder holding boost_thread-vc100-mt-1_46_1.dll - typically this folder will hold all of your boost libs and will be something like D:\Program Files\boost\boost_1_49_0\stage\lib.
Now the linker will search that folder when looking for libs, and everything should work.

code::blocks, libxml2 / libxml/parser.h: No such file or directory

Hello
I'm trying to write some tool using code::blocks, wxWidgets and libxml2 on Windows platform.
Things I've done:
copied libxml2.a, libxml2.dll.a and
other libs to MinGW lib/ folder
Wrote some headers like this in my
source file:
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
Added -lxml2 to linker
And now, when I'm trying to build this project I'm getting this error:
error: libxml/xmlmemory.h: No such file or directory
Anyone here experienced this error?
I believe that I misconfigured something but don't really know what.
Thanks for your ideas.
In general, it's better to not move things into the mingw directories, but to leave them in their own directories, and add search paths to the project properties so it knows where to look for them.
If you go into your project properties in Code::Blocks, hit the Project build options button, then inside the Linker Settings tab, add the two libraries you're linking against. Then In the Search directories tab, add the /include to compiler search locations, and optionally, add the /lib directory to Linker locations (This isn't necessary if you gave the full path to the .a in the linker settings.
Ok, I found the solution!
<libxml2/libxml/parser.h>
works perfectly

MSVC 2008 - Unresolved External errors with LIB but only with DLL, not with EXE project

I have a DLL that I am trying to link with a libjpeg LIB using MSVC 2008 that is generating Unresolved External Symbol errors for the libjpeg functions. I also have a test project that links with the exact same libjpeg library file and links without error and runs fine too.
I have triple-checked my LIB path and dependent LIBS list settings and literally copy and pasted them from the EXE project to the DLL project. I still get the errors. I do have the libjpeg include headers surrounded by extern "C" so it is not a name mangling issue and the unresolved external warnings show the "missing" libjpeg functions as undecorated (just a leading underscore and the # sign parameter byte count suffix after each name).
What could make the linker with the DLL project be unable to find the functions properly when the test EXE project has no trouble at all? I'm using the pre-compiled 32-bit static multi-threaded debug library which I downloaded from ClanLib.
Thanks,
Robert
After a lot of experimentation I found the solution. It turns out the problem was due to a difference in the calling convention used by the DLL and the LIB projects (In MSVC 2008 this is set on the Project Properties, "Configuration Properties -> C/C++ -> Advanced" setting. The DLL project was set to __stdcall and the LIB was __cdecl. Recompiling LIBJPEG with __stdcall fixed the problem.

When to include .lib and when to include .dll or both

I got a .h file, two .lib files, a .dll file and a tiny test project from a hardware vendor to talk to their hardware.
Compiling and running their test project works just fine. Noteworthy: they don't use the .dll. I can throw the dll-directory and all of it's content away, everything works just fine.
To start things off I simply copied the communication parts of their code (connect, disconnect and send a command) into my project. This is actually all that you can do. I have included the .h file and pointed to the directory containing the .lib files. Just like in the tiny test project. It all compiles, but when I try to run the project complains that it is missing the .dll file.
Can anybody explain what is happening? How are libs and dlls supposed to work?
All of this is on windows, VS2005. I compared the .vcproj files and could not find any significant differences.
The test project is statically linked - the lib is included in the exe.
Your project is dynamically linked - the dll is referenced and therefore needed at runtime.
See this Stack Overflow question for more information.
Basically the answer depends on whether you are going to use static or dynamic linking for your executable.
With static linking, you need the .h and .lib files but not the .dll files to compile and link. Your executable will be larger but you won't need any of the .h/.lib/.dll files during runtime.
With dynamic linking, you just need the .h files to compile and link. Your executable will be smaller but you will need one or both of the .dll files during runtime.
For a more detailed treatment of this from the Visual Studio perspective, check out http://msdn.microsoft.com/en-us/library/1ez7dh12.aspx -
"Dynamic linking differs from static linking in that it allows an executable module (either a .dll or .exe file) to include only the information needed at run time to locate the executable code for a DLL function. In static linking, the linker gets all of the referenced functions from the static link library and places it with your code into your executable."