Thread: Problem linking to external library

  1. #16
    Registered User
    Join Date
    Dec 2017
    Posts
    836
    If you want to try a long shot (basically idiotic) idea, try putting a copy of the dll file in the same folder as the .c file (where you are compiling it).
    I think it might need to be there (or in a standard location) for the exe to run anyway.

    BTW, are you using MinGW? Is that how you are compiling with gcc on windows?


    EDIT: Another possibility, rename the .lib file to .dll.a. Give it a try.
    Last edited by john.c; 01-08-2019 at 08:39 PM.
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  2. #17
    Registered User
    Join Date
    Jan 2019
    Posts
    9
    I tried putting the dll in the same folder, but the result did not change. I also tried the library in the same directory and linked it from there, to the same result.
    Renaming also did not work.

    I don't think that the .exe is going to need the dll. There are a bunch of executables that come with the library and they work without the dll.

    And yes: I am using MinGW, that's how I'm using gcc on Windows. I also tried compiling the example in Visual Studio 2017, which should use its own compiler and I got the same undefined reference error. When I added the lib in the project properties, It threw a world of errors, mainly complaining about the syntax in the header files, that didn't make sense.

  3. #18
    Registered User
    Join Date
    Dec 2017
    Posts
    836
    I find it surprising that you are able to run, e.g., MQTTClient_publish.exe without putting the dll (presumably paho-mqtt3c.dll) either in a standard location or in the same folder as the exe. Windows didn't work that way when I last used it, but that was a while ago. On the other hand, maybe those exes are statically linked or are taking advantage of their knowledge of the relative location of the dlls in the unzipped archive.

    At any rate, since I don't use Windows I'm basically just pulling ideas out of my butt, so I don't really expect them to work. I wish I was on Windows so I could try this stuff out. I won't waste any more of your time. Maybe a Windows person can help.
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  4. #19
    Registered User
    Join Date
    May 2009
    Posts
    3,748
    It builds for me; once, I made sure to use both an 64 bit MinGW GCC compiler and the 64 bit library.
    Edit: When I used an 32 bit mingw I got errors like the OP after the warning about skipping the library it found.

    Code:
    x86_64-w64-mingw32-gcc.exe -Wall -g -IC:\Users\stahta01\Downloads\eclipse-paho-mqtt-c-win64-1.3.0\include -c C:\Users\stahta01\devel\open_source_code\no_version_control\test\bass24\c++\basstest\testpaho\main.c -o obj\Debug\main.o
    x86_64-w64-mingw32-g++.exe -LC:\Users\stahta01\Downloads\eclipse-paho-mqtt-c-win64-1.3.0\lib -o bin\Debug\testpaho.exe obj\Debug\main.o   -lpaho-mqtt3c
    Tim S.
    Last edited by stahta01; 01-09-2019 at 04:04 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #20
    Registered User
    Join Date
    Jan 2019
    Posts
    9
    OK, thank you so much for trying it out!

    I have follow up questions: Why does it have to be compiled in two steps? Why are you using g++ for the second part?

  6. #21
    Registered User
    Join Date
    May 2009
    Posts
    3,748
    Quote Originally Posted by jak888 View Post
    OK, thank you so much for trying it out!

    I have follow up questions: Why does it have to be compiled in two steps? Why are you using g++ for the second part?
    That is the way the Code::Blocks IDE does it.
    The two part is common for many IDEs.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ Linking Problem: Unresolved External Symbol
    By neoanderson9318 in forum C++ Programming
    Replies: 5
    Last Post: 11-23-2010, 04:13 PM
  2. Linking library problem
    By seibold in forum C Programming
    Replies: 6
    Last Post: 06-28-2010, 10:48 AM
  3. Problem calling external method from within a shared library
    By Major Tom in forum C++ Programming
    Replies: 0
    Last Post: 04-21-2007, 09:14 AM
  4. Linking Problem in C++(Unresolved external symbol ....)
    By grscot in forum C++ Programming
    Replies: 2
    Last Post: 04-25-2003, 08:08 PM
  5. Library Linking problem
    By Lynchie in forum C Programming
    Replies: 3
    Last Post: 07-23-2002, 08:49 AM

Tags for this Thread