Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a written code for Windows, and now am trying to port to Linux, but not sure if it is possible or not.
"ICantFindFile.txt" is created, which means, the file couldn't be loaded. Am I picking the wrong file?

I am very new to Linux, so please bare with me if my question is too low-level.

This is the compilation output:
  Output:
    build/release-linux-ppc64/ioq3ded.ppc64
    build/release-linux-ppc64/ioquake3.ppc64
    build/release-linux-ppc64/baseq3/cgameppc64.so
    build/release-linux-ppc64/baseq3/qagameppc64.so
    build/release-linux-ppc64/baseq3/uippc64.so
    build/release-linux-ppc64/missionpack/cgameppc64.so
    build/release-linux-ppc64/missionpack/qagameppc64.so
    build/release-linux-ppc64/missionpack/uippc64.so

make[2]: Entering directory `/r/home7/XXX/ioquake3'
make[2]: `build/release-linux-ppc64/ioq3ded.ppc64' is up to date.
make[2]: `build/release-linux-ppc64/ioquake3.ppc64' is up to date.
LD build/release-linux-ppc64/baseq3/cgameppc64.so
LD build/release-linux-ppc64/baseq3/qagameppc64.so
LD build/release-linux-ppc64/baseq3/uippc64.so
LD build/release-linux-ppc64/missionpack/cgameppc64.so
LD build/release-linux-ppc64/missionpack/qagameppc64.so
LD build/release-linux-ppc64/missionpack/uippc64.so



This is the code for Windows:
//Called function
__declspec(dllexport) void UnLinkLinkroutingcache( void )
{
      //code
}

//Callback location
#include<windows.h>
typedef void (* fUnLinkLinkroutingcache_t)( void );
void fUnLinkLinkroutingcache( fUnLinkLinkroutingcache_t pUnLinkLinkroutingcache )
{
	pUnLinkLinkroutingcache(); return;
}
fUnLinkLinkroutingcache_t pUnLinkLinkroutingcache;
void callUnlinkLink(void)
{
	HMODULE hLib;
	//fUnLinkLinkroutingcache_t pUnLinkLinkroutingcache;

	hLib = LoadLibrary(TEXT("ioquake3.exe"));
	if (hLib == NULL)
		{
		//Module not found, permission denied, ...
		return 0; //inform caller of error
		}

	pUnLinkLinkroutingcache = (fUnLinkLinkroutingcache_t)GetProcAddress(hLib, TEXT("UnLinkLinkroutingcache"));
	if ( pUnLinkLinkroutingcache == NULL)
	{
		return 0;
	}

	fUnLinkLinkroutingcache(pUnLinkLinkroutingcache);
}


I tried to port this code to Linux, but I can't seem to load the exe.
//Called function
extern void UnLinkLinkroutingcache( void )

//Callback location
void callUnlinkLink(void)
{
	void* handle;
	void (*initializer)(void);
	FILE *fp;//zgzg2020

	fp = fopen("HereIsMe.txt", "a");
	if( fp != NULL )
	{
		fprintf(fp, "%d", 1 );
		fprintf(fp, "\n" );
	}
	fclose(fp);

	handle = dlopen("./ioq3ded.ppc64", RTLD_LAZY);
	if(handle == NULL) {
		// report error ...
		fp = fopen("ICantFindFile.txt", "a");
		if( fp != NULL )
		{
			fprintf(fp, "%d", 1 );
			fprintf(fp, "\n" );
		}
		fclose(fp);
		exit(1);return;
	} else {
		initializer = dlsym(handle,"UnLinkLinkroutingcache");
		if(initializer == NULL) {
			// report error ...
			fp = fopen("ICantFindFfunction.txt", "a");
			if( fp != NULL )
			{
				fprintf(fp, "%d", 1 );
				fprintf(fp, "\n" );
			}
			fclose(fp);
			exit(1);return;
		} else {
			// cast initializer to its proper type and use
			(*initializer)();
		}
		// use the result in a call to dlsym
	}
}
Posted
Updated 27-Dec-11 18:41pm
v2
Comments
ThatsAlok 28-Dec-11 1:54am    
I believe you come to wrong forum, if you ask same question in linux based forums, i believe you will receive load of replies
Richard MacCutchan 28-Dec-11 4:27am    
Why is this the wrong forum?
ThatsAlok 28-Dec-11 7:41am    
I believe Code-project moreover windows based programmer community, I believe very few programmer would be here who work on both Windows and Linux. that's why i commented better post your question in Linux c++ based community to get quick reply. i must admit being programmer for more than 8 year, I haven't taken flavor of c++ programming in Linux.

I hope that answer your question
Richard MacCutchan 28-Dec-11 7:54am    
Since we have a Linux forum in the discussion forums section I think your assumption is wrong. I (and others here) have worked on Windows, UNIX and Linux so the question was appropriate.

ThatsAlok 28-Dec-11 9:27am    
as mentioned earlier, i said there are few people working on Linux here,as it is window dominated community ( Is i am wrong saying that) though you know Linux, are you available 24X7. also if you read comment i posted earlier if the guy posted in Linux based community, he would have got early reply ( that my main intention. apologies if it hurt your and any other multi-plateform programmer here.

More over i couldn't find any Linux based forum here, if possible provide me link of same or you referring to Linux tag mentioned with the post?

You should be checking dlerror() as described here[^] when your dlopen() or dlsym() call fails. There is no point in posting vague messages when system or api calls fail.
 
Share this answer
 
v3
I suggest using dlerror[^] to see if there is some information about why dlopen failed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900