Jump to content
  • Advertisement
Sign in to follow this  
Narcis

Compiling DLL Error

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
I can think of four things:

- The implementation is not a typo, and it should be:
void DLL_EXPORT Write(const 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 file::Write(const char * buffer, FILE * stream) {
// ...
}
- You haven't linked in the proper lib file.


jfl.

Share this post


Link to post
Share on other sites
- 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.

Share this post


Link to post
Share on other sites
Don't mean to double post, but as I expected, the typo you found was the problem. Apreciate the looking.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!