How to Specify a DLL in a Plain Vanilla C Program

General questions regarding the usage of CodeLite
User avatar
ColleenKobe
CodeLite Expert
Posts: 130
Joined: Wed Mar 30, 2016 4:31 pm
Genuine User: Yes
IDE Question: C++
Contact:

How to Specify a DLL in a Plain Vanilla C Program

Post by ColleenKobe »

I am trying to compile a plain vanilla C program in CodeLite, using TDM-GCC as the compiler. I'm making a Release (not Debug) build.

The compiler is giving me an error I don't know how to fix, and I hope one of you can help me fix it.

Here is my main program.

Code: Select all

    #include <stdio.h>
    #include <stdlib.h>

    #include "datatypes.h"
    #include "printmsgs.h"
    #include "ut-simple.h"

    int main(int argc, char **argv)
    {

        int   Ave =  0;
        long  Sum =  0;
        int   N1  = 30;
        int   N2  = 50;

        printf("Entering TestingReadingNetbeansDLL main.\n");

        printf("N1 =    %12d \n", N1);
        printf("N2 =  + %12d \n", N2);
        printf("        ---- \n");

        Sum = ut_Calculate_Sum (N1, N2);
        printf("       %12ld  = sum \n\n", Sum);

        Ave = ut_Calculate_Average (N1, N2);
        printf("        %12d  = Average\n\n", Ave);

        printf("Done!\n");
        return 0;
    }
This program calls ut_Calculate_Sum and ut_Calculate_Average in libSimpleUtil.dll

To set the make settings, I went to Settings, Build Settings, and clicked on "gnu gcc," and clicked on the "Tools" tab. I changed the "-j 4" (which gave me errors) to C:\TDM-GCC-32\bin\mingw32-make.exe and clicked OK.

To tell the compiler where to find libSimpleUtil.dll, I right-clicked on the Project name, clicked Settings, clicked Linker, and clicked in the Libraries box. I navigated to F:\Prototypes_CPP\TestingReadingNetbeansDLL\DLLCaller\Release, the folder in which I thought the EXE would be built.

But when I compile, I get the following error message.

Code: Select all

    C:\Windows\system32\cmd.exe /C C:/TDM-GCC-32/bin/mingw32-make.exe -e -f  Makefile
    "----------Building project:[ DLLCaller - Release ]----------"
    mingw32-make.exe[1]: Entering directory 'F:/Prototypes_CPP/TestingReadingNetbeansDLL/DLLCaller'
    gcc -o ./Release/DLLCaller @"DLLCaller.txt" -L.  -lF:/Prototypes_CPP/TestingReadingNetbeansDLL/DLLCaller/Release
    C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lF:/Prototypes_CPP/TestingReadingNetbeansDLL/DLLCaller/Release
    collect2.exe: error: ld returned 1 exit status
    mingw32-make.exe[1]: *** [Release/DLLCaller] Error 1
    mingw32-make.exe: *** [All] Error 2
    DLLCaller.mk:80: recipe for target 'Release/DLLCaller' failed
    mingw32-make.exe[1]: Leaving directory 'F:/Prototypes_CPP/TestingReadingNetbeansDLL/DLLCaller'
    Makefile:4: recipe for target 'All' failed
    ====0 errors, 0 warnings====
How do I fix this?
User avatar
ColleenKobe
CodeLite Expert
Posts: 130
Joined: Wed Mar 30, 2016 4:31 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: How to Specify a DLL in a Plain Vanilla C Program

Post by ColleenKobe »

I found out what I was doing wrong, and am including the solutions here in case someone else has this problem.

Problem summary:

I had a plain vanilla C library compiled in Netbeans using MinGW, and it compiled into a DLL.

I had a main program, also plain vanilla C, compiled in CodeLite, using TPM-GCC.

There were a couple of problems with how I had things set up, so either the compiler couldn't compile, or the executable couldn't run.

Solutions (both were required):

1) The program and DLL have to be compiled to the same architecture. I had not paid attention to that, and my DLL was compiling to 32 bits and the program was compiling to 64 bits. I changed the main program to compile to 32 bits.

2) In CodeLite, I had the compiler settings wrong. I fixed them by clicking Settings, Build Settings, and "gnu gcc." Beside "C++ Compiler," I navigated to and entered "C:/TDM-GCC-32/bin/g++.exe". Beside "C Compiler," I navigated to and entered "C:/TDM-GCC-32/bin/gcc.exe."

After cleaning and building, the program ran perfectly.

I hope this helps someone else! :)
Post Reply