curl / Mailing Lists / curl-library / Single Mail


Re: Undefined Reference Error when Linking .OBJ file

From: Luca Di Rocco via curl-library <>
Date: Wed, 10 Apr 2019 00:33:32 +0200

On Tue, 9 Apr 2019 at 14:24, Dan Gribble via curl-library
<> wrote:
> Thanks for the response Daniel. I can compile and link using the -I and -lcurl parameters when using gcc within CYGWIN, hoever, I have a specific requirement at my place of work which means I must use WATCOM to compile and link.
> I appreciate this may not be your area of expertise but I can compile my test.cpp program fine when supplying the path to the various cURL header files, however, the problem comes at the linking stage. The -lcurl parameter is not supported by WATCOM.
> WATCOM has a few LIB/LIBPath commands, but I can't find any other .lib files in the package I downloaded from the cURL website.
> I have a libcurl.a and a libcurl.dll.a file in my Windows 7 cURL /lib folder, but that it is it.
> Do I need to download anything else (.lib, .dll etc) which I need to refer to when linking?

Hello Dan,

You can link by using watcom linker, as follows:
wlink Name mytest.exe File mytest.obj LIBPATH path_to_libcurl_folder
LIBRARY libcurl.a

However, looking at the error message attached to your previous email,
I'm pretty sure that you will get exactly the same linking errors.

The problem is due to the default "calling convention" of Watcom
compiler being different from other compilers for win32 and causing a
mismatch between the symbols generated by the Watcom compiler (with an
underscore at the end) and the symbol in the libcurl.a static library
(having an underscore in front, according to the cdecl convention).
Actually this mismatch is there to prevent from linking software that
would not work, due to differences in the ways registers and stack are
managed by a compiled function and by the compiled software invoking
that function (Watcom default calling conventions uses registers for
parameters and result, while cdelc uses the stack in win32).
Even fixing the issue with curl library functions (for example by
putting __cdecl between the return type and the name of each exported
function in the header files or curl library), there would still be
many issues with other external symbols defined in the curl static
library, because of a mismatch with Watcom libraries (e.g. with
standard c function). Moreover, linking with static curl library would
require to include also the static libraries used to build curl static
library (e.g. libssh2, libz, libssl, libcrypto, libnghttp2. etc), and
there would be linking issues with those libraries too. Unfortunately,
static libraries may not be portable across different compilers,
especially with win32.
So, if you really need to use curl static library with Watcom
compiler, you should build curl static library (and the other needed
libraries) directly with Watcom compiler. I don't know if that is
feasible, but for sure it would take quite some time.

A simpler alternative, if compatible with your requirements, would be
using curl dynamic library (DLL), which has no static (and less
compiler) dependencies.
There are still some little issues with symbols, due to the
peculiarities of watcom compiler, but those are easy to solve.

You would need first to generate an import lib file for watcom
compiler (let's call it watcom_libcurl.dll.lib) from libcurl.dll, by
using watcom wlib tool:
wlib -n watcom_libcurl.dll.lib +libcurl.dll

And then compile your code with the following command (assuming WATCOM
variable points to the root folder of Watcom compiler and CURL_LIBRARY
to the root of curl library)

wcl386 -i=%WATCOM%\h -i=%WATCOM%\h\nt -i=%CURL_LIBRARY%\include
-DNDEBUG -DWIN32 -bt=nt -l=nt -5s mytest.cpp watcom_libcurl.dll.lib

Please, note that the -5s option is crucial, because it makes the
parameters exchanged via the stack.

Of course your app will not be self contained and will require
libcurl.dll in addition other windows dll. Make sure libcurl.dll is in
the PATH or in the same directory of your executable.

Please, let me know if things will work for you or you may need further help.

Kind regards,
Received on 2019-04-10