I am trying to use the POCO C++ library in my existing Windows CE project on Visual Studio 2008.
I have compiled the POCO library using the provided .bat files. I used the one nammed build_CE_vs90.cmd and it successfully generated several .lib files.
However a header of the POCO library (Foundation.h) has a pragma to automatically link the right .lib file :
#if defined(_MSC_VER)
#if defined(POCO_DLL)
#if defined(_DEBUG)
#define POCO_LIB_SUFFIX "d.lib"
#else
#define POCO_LIB_SUFFIX ".lib"
#endif
#elif defined(_DLL)
#if defined(_DEBUG)
#define POCO_LIB_SUFFIX "mdd.lib"
#else
#define POCO_LIB_SUFFIX "md.lib"
#endif
#else
#if defined(_DEBUG)
#define POCO_LIB_SUFFIX "mtd.lib"
#else
#define POCO_LIB_SUFFIX "mt.lib"
#endif
#endif
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Foundation_EXPORTS)
#pragma comment(lib, "PocoFoundation" POCO_LIB_SUFFIX)
#endif
#endif
The problem is that POCO_LIB_SUFFIX is defined as "mtd.lib" and I have no "mtd" version of the lib in the directory where the .lib files are. I only have PocoFoundation.lib and PocoFoundationd.lib, but no PocoFoundationmtd.lib, which is causing an error while linking because the file is not found.
I have compiling my project using :
POCO_STATIC
POCO_NO_UNWINDOWS
I openned the build .bat script and it does contain the argument "static_mt" passed to the main build file :
#echo off
buildwin 90 build static_mt both WinCE samples
What am I missing ? Thank you.
You're compiling your project with DEBUG config, change it and undef POCO_STATIC (it's the MultiThread build), for some reason you compiled the shared version, that's why you've the .lib file without any suffix.
Related
I am trying to use the ADTF streaming library in my project. When I am including the lib, I get the LNK1181 error. The library comes with the headers, the lib files and dll files.
I have added the path inside the C/C++ -> General -> Additional Include Directories.
In addition, I have added the library inside the Linker -> Input -> Additional Dependencies.
Here is also the error screenshot.
Update: I have changed the location of the dll and the libs to my project path and include it again. It does not complain now about the lib itself. Now I am getting an error LNK2001. I believe it is also a linker error.
And here where it all goes wrong!
Update 2: After I see the full log of the build. This appears, I think this means, the linker can't find my lib. Is that right?
The main application code is as this:
#include "pch.h"
#include <iostream>
#include "adtf_streaming.h"
using namespace adtfstreaming;
int main()
{
std::cout << "Hello World!\n";
IADTFFileReader *pFileReader = IADTFFileReader::Create();
}
and the header file which is trying to read/ import my lib is
#ifndef _ADTF_STREAMING_LIBRARY_DLL_
#define _ADTF_STREAMING_LIBRARY_DLL_
#ifdef WIN32
#ifdef STREAMINGLIB_EXPORTS
#pragma message ("Create ADTF Streaming Library ")
// export symbols
#define DOEXPORT __declspec( dllexport )
#else
#pragma message ("Use dynamic ADTF Streaming Library ")
#ifdef _DEBUG
#pragma comment( lib, "adtfstreamingD_290.lib" )
#else
#pragma comment( lib, "adtfstreaming_290.lib" )
#endif
#define DOEXPORT __declspec( dllimport )
#endif
#else
#ifdef STREAMINGLIB_EXPORTS
#define DOEXPORT __attribute__ ((visibility("default")))
#else
#pragma comment( lib, "adtfstreaming_290.lib" )
#define DOEXPORT __declspec( dllimport )
#endif
#endif
//standard includes
#include <stdlib.h>
#include <string.h>
//adtf base types and errors
#include "adtf_base_ref.h"
//streaming lib version
#include "adtf_streaming_version.h"
//adtf streaming lib package headers
#include "adtf_streaming_pkg.h"
#endif //_ADTF_STREAMING_LIBRARY_DLL_
You need to specify the Additional Library Directories, in Linker properties, to set the directory where you have the lib file. You don't need to include the libs in Additional Dependencies because you are doing it in the lib header file #pragma comment( lib, "adtfstreamingD_290.lib" ) when you compile your app in debug or #pragma comment( lib, "adtfstreaming_290.lib" ) when you compile in release. But you need to specify where are these libs in Additional Library Directories.
If you see the lib include file, you see that if STREAMINGLIB_EXPORTS macro is defined all functions with DOEXPORT modifier are exported functions #define DOEXPORT __declspec( dllexport ). But if this macro is not defined #define DOEXPORT __declspec( dllimport ), the same functions are imported functions. It is because the dll needs to specify that this functions are exported functions, so in the dll code someone has defined this macro. Because in your code you have not (and you must not do) define this macro, this functions are imported functions.
ADTF Streaming Library requires VS 2010 and is not compatible with other versions! So make sure to use it with v100 build tools. Or change to ADTF File Library a.k.a. IFHD, which is the v141 compatible successor and works with ADTF 2.x and ADTF 3.x as well. Note that the Lib comes completely open source licensed. See ADTF .dat trace file reader for some overview
I found the answer to the problem. Well, a combination of problems.
The library was built to support 0x86 machines only. I have built it again to support 0x64 and it worked.
P.S. It worked on Visual Studio 2017 too, unfortunately the documentation is poor and lacks information.
I want to create a DLL project and add it implicitly to a win32 app. I have a header.h file and a func.c file to generate DLL.
header.h:
#include <Shlwapi.h>
#include <header.h>
#ifdef LIBRARY_EXPORTS
# define LIBRARY_API __declspec(dllexport)
#else
# define LIBRARY_API __declspec(dllimport)
#endif
LIBRARY_API VOID __cdecl MyFunction(WCHAR *wchSource, WCHAR *wchDestination, WCHAR *wchKey);
and func.c:
#include <Shlwapi.h>
VOID MyFunction(WCHAR *wchSource, WCHAR *wchDestination, WCHAR *wchKey)
{
// Some code here.
}
so my project builds DLL successfully but there is no .lib file beside it.
Is my code wrong or I should change some properties of my project? Maybe in Linker part?
My project is in visual studio 2010.
Using Visual Studio 2013, I am currently trying to generate a .dll with C++ Code, which i want to include into a VB.NET project. To create the .dll i tried to follow these tutorials:
http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c9855/DLL-Tutorial-For-Beginners.htm
http://msdn.microsoft.com/de-de/library/ms235636.aspx
For now my .dll Project contains only the following files:
External Dependencies (auto generated by VS2013)
Header Files: stdafx.h, targetver.h (auto generated)
dllmain.cpp with default entry point Method DllMain and stdafx.cpp (auto generated)
MyDLL.cpp and containing the implementation of my methods which should be exported (for now one void method without parameters)
Headerfile MyDLL.h
Source.def (i only added the .def file after i tried using the __declspec(dllexport) statement)
MyDll.h contains:
#ifndef _DLL_MYDLL_H_
#define _DLL_MYDLL_H_
#include <iostream>
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
extern "C"
{
DECLDIR void MyMethod();
}
#endif
MyDLL.cpp contains:
#include "stdafx.h"
#include "MyDLL.h"
#define DLL_EXPORT
extern "C"
{
void MyMethod(){
//my code
}
When i create the .dll (by using "build > build solution" in VS2013) it compiles without errors and warnings. However, when i try to set a reference in my VB-Project by using "project > add reference" and selecting the .dll that was created in the DEBUG-Folder of my DLL-Project, i get an error stating that the reference could not be added and that i should make sure that the file is accessible and that it is a valid assembly or COM component.
Am i missing some vital settings in my dll/vb project here? Thanks in advance for your advice.
I've created a DLL a file, and in the header file I see :
#ifdef WIN32DLL_EXPORTS
I don't understand what does it mean and where/how we can set up WIN32DLL_EXPORTS.
if I use:
#ifdef WIN32DLL_EXPORTS
#define WIN32DLL_API __declspec(dllexport)
#else
#define WIN32DLL_API __declspec(dllimport)
#endif
WIN32DLL_API int testSum(void);
testSum is considered as __declspec(dllimport). So I think my project is not set to WIN32DLL_EXPORTS? How can I change this?
There is a comment block immediately above the line you quoted. Read it.
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the WIN32DLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// WIN32DLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef WIN32DLL_EXPORTS
#define WIN32DLL_API __declspec(dllexport)
#else
#define WIN32DLL_API __declspec(dllimport)
#endif
You can either:
define WIN32DLL_EXPORTS in the project's Properties > Configuration Properties > C/C++ > Preprocessor > Preprocessor definitions.
if you use a precompiled header (e.g. stdafx.h) then you can also define WIN32DLL_EXPORTS
there with a #define statement.
I have a static S.lib that is used by my D.dll.
I'm trying to use #pragma detect_mismatch to make sure that both were compiled under the same release or debug settings.
I've followed Holger Grund's instructions here
http://boost.2283326.n4.nabble.com/Boost-and-Microsoft-s-SECURE-SCL-td3025203.html
dumpbin on S.lib shows:
Linker Directives
-----------------
/FAILIFMISMATCH:"COMPILED_DEBUG=1"
/INCLUDE:_dll_impl_interface_mismatch_check
/DEFAULTLIB:"MSVCRTD"
/DEFAULTLIB:"OLDNAMES"
I compile D.dll successfully, which should not happen.
dumpbin on D.dll's D.lib shows:
Linker Directives
-----------------
/FAILIFMISMATCH:"COMPILED_DEBUG=2"
/INCLUDE:_dll_impl_interface_mismatch_check
/DEFAULTLIB:"uuid.lib"
/DEFAULTLIB:"uuid.lib"
/FAILIFMISMATCH:"_MSC_VER=1600"
/FAILIFMISMATCH:"_ITERATOR_DEBUG_LEVEL=2"
/DEFAULTLIB:"msvcprtd"
/DEFAULTLIB:"MSVCRTD"
/DEFAULTLIB:"OLDNAMES"
Any help would be greatly appreciated.
EDIT:
I accidentally defined the symbol 'dll_impl_interface_mismatch_check' in BOTH my static library and my consuming DLL. This meant that the symbol was not looked for in the static library S.lib, and the mismatch directive was never found. I think.
I'm just guessing here - I'll have to experiment with this tonight.
Holger Grund's instructions are designed for objects that depend on the DLL. In your case the DLL depends on the static lib.
So, I'm guessing that you want the _dll_impl_interface_mismatch_check object to be added to the static lib rather than the DLL. So instead of:
extern "C" const char dll_impl_interface_mismatch_check=0;
cl /c /Zl foo.cpp
lib D.lib foo.obj
try:
extern "C" const char dll_impl_interface_mismatch_check=0;
cl /c /Zl foo.cpp
lib S.lib foo.obj
You have to build a string with the preprocessor that represents your build settings, and use that string with #pragma detect_mismatch.
E.g.
#if defined(_DEBUG)
#define FOO_DEBUG_PART "_debug"
#else
#define FOO_DEBUG_PART "_release"
#endif
#if defined(_MT)
#define FOO_CRT_PART1 "_MT"
#else
#define FOO_CRT_PART1 "_st"
#endif
#if defined(_DLL)
#define FOO_CRT_PART2 "_DLL"
#else
#define FOO_CRT_PART2 "_LIB"
#endif
// ...
#define FOO_BUILD_SETTINGS FOO_DEBUG_PART FOO_CRT_PART1 FOO_CRT_PART2 /* ... */
#pragma detect_mismatch("foo_build_settings", FOO_BUILD_SETTINGS)
The IMO better solution though is to use #pragma comment(lib) to link to your libraries, and then build a similar string and use it as part of the file name of the lib:
// build FOO_BUILD_SETTINGS like above
#pragma comment(lib, "mylib" FOO_BUILD_SETTINGS)
That way you cannot use the wrong library (unless you either change the code or the lib is created with the wrong file name ... or renamed afterwards). And of course, if you're as paranoid as I am, you can always do both :)