Skip to main content
gamedev.net
🔒 Locked

Compiling DLL Error

Started by Narcis 3 replies 900+ views
Original Post
Narcis
Narcis
I'm having a relitivly easy to debug, but prooving difficult to find, error when compiling a dll.
Linking console executable: C:\CLibraries\Projects\DLLs\CommenLib Test\console.exe
.objs\main.o:main.cpp:(.text+0x158): undefined reference to `file::Write(char const*, _iobuf*)'
collect2: ld returned 1 exit status
The above error came from compiling the test application using it. Test Application Source
[source lang=cpp]
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <CommenLib.h>

int main()
{
	FILE * fp = file::Open("test.txt", "w", false);
	file::Write("test :)", fp);
	file::Close(fp);
	return 0;
}

DLL Header (CommenLib.h) - Only showing relevant prototype information.
[source lang=cpp]
void DLL_EXPORT Write(const char * buffer, FILE * stream);

DLL Reference to file::Write
[source lang=cpp]
void DLL_EXPORT Write(char* buffer, FILE * stream)
{
    fwrite(buffer, 1, strlen(buffer), stream);
}

And it is inside the file namespace.
jflanglois
jflanglois
I can think of four things:

- The implementation is not a typo, and it should be:
void DLL_EXPORT Write(<font color="red">const</font> char * buffer, FILE * stream) {  // ...}
- Something is funky with DLL_EXPORT, what is it exactly? I assume that it is a #define for __declspec( dllexport/dllimport )?

- The implementation of Write is written outside of the file namespace, so you need to either enclose the definitions in the file namespace, or fully name the function:
void DLL_EXPORT <font color="red">file::</font>Write(const char * buffer, FILE * stream) {  // ...}
- You haven't linked in the proper lib file.


jfl.
Narcis
Narcis
- DLL_EXPORT would be __declspec(dllexport)

- Write IS inside the file namespace, just didn't see it fit to copy everything irrelevent of the matter :P

- Linked properly :)

I've checked pretty much every obvious answer.

Edit: That first one (typo), might be the problem... checking now.
Narcis
Narcis
Don't mean to double post, but as I expected, the typo you found was the problem. Apreciate the looking.
jflanglois
jflanglois
That's hardly a double post. Glad you found the problem.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.