Author Topic: Building Dynamic Library  (Read 522 times)

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 26
Building Dynamic Library
« on: July 30, 2017, 07:31:07 pm »
main.cpp:
Code: [Select]

#include "main.h"

// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
    MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}

extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}

Build log:

Code: [Select]

-------------- Clean: Release in example_mic_dyn (compiler: Microsoft VC 2017)---------------

Cleaned "example_mic_dyn - Release"

-------------- Build: Release in example_mic_dyn (compiler: Microsoft VC 2017)---------------

cl.exe /nologo  /MD /Ox /W3 /DBUILD_DLL /DNDEBUG    /I"..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\atlmfc\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\lib\x64" /I"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64" /I"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64" /c main.cpp /Foobj\Release\main.obj
main.cpp
link.exe /dll /nologo /LIBPATH:"..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\include" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\atlmfc\include" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\lib\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64" /out:bin\Release\example_mic_dyn.dll user32.lib obj\Release\main.obj  /INCREMENTAL:NO
   Creating library bin\Release\example_mic_dyn.lib and object bin\Release\example_mic_dyn.exp
Output file is bin\Release\example_mic_dyn.dll with size 8.50 KB
Running target post-build steps
mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2
Execution of 'mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2' in 'C:\Users\lucao\Desktop\example_mic_dyn' failed.
« Last Edit: July 30, 2017, 09:06:02 pm by lbertolotti »
Languages: C/C++, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10118
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1414
Re: Building Dynamic Library
« Reply #2 on: July 31, 2017, 10:01:39 am »
There is clearly written what the problem is:
Quote
Execution of 'mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2' in 'C:\Users\lucao\Desktop\example_mic_dyn' failed.
You have to find out why this fails...
I don't know how we can help with this problem.
Probably the mt.exe is not in the PATH?

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Building Dynamic Library
« Reply #3 on: July 31, 2017, 03:55:06 pm »
Adding C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64 to compiler additional paths:
Code: [Select]
-------------- Clean: Release in example_mic_dyn (compiler: Microsoft VC 2017)---------------

Cleaned "example_mic_dyn - Release"

-------------- Build: Release in example_mic_dyn (compiler: Microsoft VC 2017)---------------

cl.exe /nologo  /MD /Ox /W3 /DBUILD_DLL /DNDEBUG    /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um" /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86" /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\atlmfc\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\lib\x64" /I"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64" /I"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64" /I"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /I"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /c main.cpp /Foobj\Release\main.obj
main.cpp
link.exe /dll /nologo /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um" /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86" /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\include" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\atlmfc\include" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\lib\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /out:bin\Release\example_mic_dyn.dll user32.lib obj\Release\main.obj  /INCREMENTAL:NO
   Creating library bin\Release\example_mic_dyn.lib and object bin\Release\example_mic_dyn.exp
Output file is bin\Release\example_mic_dyn.dll with size 8.50 KB
Running target post-build steps
mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2
bin\Release\example_mic_dyn.dll.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
Process terminated with status 31 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Languages: C/C++, Python and R

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1414
Re: Building Dynamic Library
« Reply #4 on: July 31, 2017, 04:25:38 pm »
what if you call this
Code: [Select]
mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2from a command line inside your project folder?

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1414
Re: Building Dynamic Library
« Reply #5 on: July 31, 2017, 04:31:29 pm »
Also, does the file "bin\Release\example_mic_dyn.dll.manifest" exists? If not you have your answer....

Offline sodev

  • Multiple posting newcomer
  • *
  • Posts: 86
Re: Building Dynamic Library
« Reply #6 on: July 31, 2017, 08:07:53 pm »
Where do these paths come from? I'm using the following Postcommand to embed the manifest into an exe:

Code: [Select]
mt.exe -manifest $exe_output.manifest -outputresource:$exe_output;1
I don't know what working directory CodeBlocks sets for the Postcommands, my output directory is the one with the project file and the macros evaluate to current directory in my case.

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Building Dynamic Library
« Reply #7 on: July 31, 2017, 10:25:47 pm »
Quote
what if you call this
Code: [Select]

mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2

from a command line inside your project folder?

How am I supposed to do that? I have 3 mt.exe in Windows Kits: an arm64, x64 and a x86 version. And no, there's no "bin\Release\example_mic_dyn.dll.manifest", but that doesn't explains why the file was not generated. Also, this is the standard dll project in Code::Blocks.
Languages: C/C++, Python and R

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1414
Re: Building Dynamic Library
« Reply #8 on: July 31, 2017, 10:29:40 pm »
Quote
Where do these paths come from?
they are coming from your input
Quote
mt.exe -manifest $exe_output.manifest -outputresource:$exe_output;1

Code: [Select]
$exe_outputis expanded to this path.
This is a advanced compiler variable so you are messing with the advanced compiler settings? (Settings->Compiler->Global compiler settings->Other settings->Advanced options)

you have probably to set it like this
Code: [Select]
mt.exe -manifest $exe_name.manifest -outputresource:$exe_output;1and put your manifest file in the root project folder with the name "example_mic_dyn.manifest"

I have no idea what a manifest file does, and how the naming convention are... I am only guessing on the things you say, and you don't give many information...

Can you not use a post build step for this? So you could use normal variable expansion: http://wiki.codeblocks.org/index.php/Variable_expansion
so in the post build steps you have something like
Code: [Select]
mt.exe -manifest $exe_output.manifest -outputresource:$exe_output;1

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1414
Re: Building Dynamic Library
« Reply #9 on: July 31, 2017, 10:31:39 pm »
Quote
And no, there's no "bin\Release\example_mic_dyn.dll.manifest", but that doesn't explains why the file was not generated.

They are not auto generated. You have to make them by your own...

Quote
How am I supposed to do that? I have 3 mt.exe in Windows Kits: an arm64, x64 and a x86 version.
Obviously you use the application for your target architecture...

Offline sodev

  • Multiple posting newcomer
  • *
  • Posts: 86
Re: Building Dynamic Library
« Reply #10 on: August 01, 2017, 12:25:32 am »
I know where MY paths are coming from, thanks, but i dont know where HIS paths are coming from ;). I am using the macros and they expand to the proper location for me. I guessed he hardcoded the paths to wrong values, because he is already using a very strange compiler setup with relative paths to compiler internal directories as you can see from the build log (and i remember him from another thread where he displayed his strange compiler setup).

And yes, you have to use the mt.exe from the SDK that you are linking against, and no, the manifest should get created automatically, at least thats what MSDN says. However it doesnt hurt to specify /MANIFEST explicit in the linker options to enable it. And the default name for it is indeed <full name with extension>.manifest, most important use of the manifest is to enable proper UI dlls or your application looks like Windows 3.1.

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1414
Re: Building Dynamic Library
« Reply #11 on: August 01, 2017, 10:04:37 am »
@sodev: sorry, i thought your response was from lbertolotti  ::) I think you know more from this, i have no idea from the visual studio compiler so i am out :)

Offline cacb

  • Regular
  • ***
  • Posts: 346
Re: Building Dynamic Library
« Reply #12 on: August 01, 2017, 11:21:51 am »
Running target post-build steps
mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2
Execution of 'mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2' in 'C:\Users\lucao\Desktop\example_mic_dyn' failed.

I think manifest files are only "useful" if you use GUI in the DLL, perhaps you do.

For targets with GUI and MSVC compiler I use the following in the Code::Blocks post build step
Code: [Select]
mt.exe /nologo /manifest $(TARGET_OUTPUT_FILE).manifest /outputresource:$(TARGET_OUTPUT_FILE);1
Essentially linking the manifest data into the executable. The effect is that the Windows GUI uses the current theme etc.

In my case with MSVC2013 I find mt.exe in C:\Program Files (x86)\Windows Kits\8.1\bin\x64 so it must be in the path
« Last Edit: August 01, 2017, 11:26:38 am by cacb »

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Building Dynamic Library
« Reply #13 on: August 06, 2017, 07:46:02 pm »
Setting /MANIFEST in linker settings solved the problem:
Code::Blocks build log:
Code: [Select]
-------------- Clean: Release in example_mic_dyn (compiler: Microsoft VC 2017)---------------

Cleaned "example_mic_dyn - Release"

-------------- Build: Release in example_mic_dyn (compiler: Microsoft VC 2017)---------------

cl.exe /nologo  /MD /Ox /W3 /DBUILD_DLL /DNDEBUG    /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um" /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86" /I"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\atlmfc\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\lib\x64" /I"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64" /I"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64" /I"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /I"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /c main.cpp /Foobj\Release\main.obj
main.cpp
link.exe /dll /nologo /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um" /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86" /LIBPATH:"..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\include" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\atlmfc\include" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.25017\lib\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\arm64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" /out:bin\Release\example_mic_dyn.dll user32.lib obj\Release\main.obj  /INCREMENTAL:NO /MANIFEST
   Creating library bin\Release\example_mic_dyn.lib and object bin\Release\example_mic_dyn.exp
Output file is bin\Release\example_mic_dyn.dll with size 8.50 KB
Running target post-build steps
mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2
Process terminated with status 0 (0 minute(s), 5 second(s))
0 error(s), 0 warning(s) (0 minute(s), 5 second(s))

Windows cmd:
Code: [Select]
C:\Users\lucao\Desktop\example_mic_dyn>PATH=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64

C:\Users\lucao\Desktop\example_mic_dyn>mt.exe /nologo /manifest "bin\Release\example_mic_dyn.dll.manifest" /outputresource:"bin\Release\example_mic_dyn.dll";2


https://msdn.microsoft.com/en-us/library/windows/desktop/aa375365(v=vs.85).aspx
example_mic_dyn.dll.manifest:
Code: [Select]
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

Languages: C/C++, Python and R