Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:28:48+00:00 2026-06-03T01:28:48+00:00

As per title, I’m trying to build a DLL using C and link it

  • 0

As per title, I’m trying to build a DLL using C and link it from a C++ project. I read and followed different tutorials on internet but everytime there is something missing and I don’t understand what.

Here’s what I did, step by step:

I created a new Win32 project, named testlib, then, from the wizard, I chose “DLL” and “Empty project”.

Added a header:

//testlib.h

#include <stdio.h>

__declspec(dllexport) void hello();

Added a source; since I want it to be a C source I read I should simplly rename the .cpp file in .c, so

//testlib.c

#include "testlib.h"

void hello() {
    printf("DLL hello() called\n");
}

Build succeded.

Now I would like to use my useful dll in another project.

Then: new project (testlibUse). This time I selected “Empty project”.
No need to add an header, just created a cpp source

//main.cpp
#include <testlib.h>

int main() {
    hello();
}

Then:

  • I added the path to the folder where is testlib.dll in Properties->VC++ directories->Executable directories

  • I added the path to the folder where is testlib.h in Properties->VC++ directories->Include directories

  • I added the path to testlib.lib (included extension) in Properties->Linker->Input->Additional dependencies

I tried to build but I got a linker error:

LINK : C:\path\testlibUse\Debug\testlibUse.exe not found or not built by the last incremental link; performing full link
main.obj : error LNK2019: unresolved external symbol “void __cdecl hello(void)” (?hello@@YAXXZ) referenced in function _main
C:\path\testlibUse\Debug\testlibUse.exe : fatal error LNK1120: 1 unresolved externals

If I go back to testlib, rename back testlib.c in testlib.cpp and rebuild the dll, then I am able to build testlibUse but I get a “dll not found” error at runtime.

I tried also to change the configurations of both projects in “Release” (changing the path where needed), but nothing changed.

Sorry for the long post but I think it was necessary to write down exactly what I did.

Any suggestions?

Besides, are there any configuration parameters I need to change if I want to use my dll in a Qt project?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:28:49+00:00Added an answer on June 3, 2026 at 1:28 am

    You have several problems:

    1. The header file should mark the functions as exported when being compiled in the DLL but imported when being compiled by a library user.
    2. The header file should wrap the function declarations in an extern "C" block when being compiled as C++ to ensure that the names do not get mangled
    3. The DLL is not on your executable’s library search path, so it can’t be found at runtime.

    To fix (1) and (2), rewrite your header like this:

    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // Assume this symbol is only defined by your DLL project, so we can either
    // export or import the symbols as appropriate
    #if COMPILING_MY_TEST_DLL
    #define TESTLIB_EXPORT __declspec(dllexport)
    #else
    #define TESTLIB_EXPORT __declspec(dllimport)
    #endif
    
    TESTLIB_EXPORT void hello();
    // ... more function declarations, marked with TESTLIB_EXPORT
    
    #ifdef __cplusplus
    }
    #endif
    

    To fix (3), copy the DLL into the same folder as your executable file. The “executable directories” setting you’re setting doesn’t affect DLL searching — see MSDN for a detailed description of how DLLs are searched for. The best solution for you is to copy your DLL into the directory where your executable file lives. You can either do this manually, or add a post-build step to your project that does this for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Visual Studio 2005 As per the title; MSDN and google can't tell me,
Hi and good day everyone, as per above title, I was trying to handle
As per title. Using native ID's The only thing I can think to do
Per title - I am using the official mongodb driver and I am looking
As per title, I am simply trying to install pecl_http extension for php in
Per the title, I'm trying to get my GUI change with RadioButton selection. More
As the title says I want to give different bg colors per 2 lists
As per title createobject scripting.filesystemobject IIS 7 - vbscript code is always trying to
As per title i am trying to measure page performance in IE6 that has
I'm trying to get my Frames-Per-Second readout to appear in my window title. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.