Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Compiling error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 06 March 2014 - 10:28 AM

When I try to compile project(Eclipse on Ubuntu 13.10 x64) it says about 

 

as_thread.o : undefined pointer to symbol «pthread_rwlock_wrlock@@GLIBC_2.2.5»

 

Using static library attached to project,version 2.28.1

Is there any possible fixes for it? I tried to add -pthread flag to both compilation of library and compilation of project, but it hadn't helped.

Sorry if theres already existing post for this problem.



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3239

Like
0Likes
Like

Posted 06 March 2014 - 12:16 PM

I believe the correct flag to add to the linker is -lpthread, at least that is what is done in the gnuc makefile.

 

If you can't get it to work you can also turn off multithreading completely by compiling the angelscript library with the preprocessor macro defined AS_NO_THREADS (e.g. with commandline flag -DAS_NO_THREADS)


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 06 March 2014 - 12:44 PM

I believe the correct flag to add to the linker is -lpthread, at least that is what is done in the gnuc makefile.

 

If you can't get it to work you can also turn off multithreading completely by compiling the angelscript library with the preprocessor macro defined AS_NO_THREADS (e.g. with commandline flag -DAS_NO_THREADS)

Changed project settings, still don't work.

Neither with -lpthread nor -DAS_NO_THREADS nor both


Edited by jammer312, 06 March 2014 - 12:44 PM.


#4 Andreas Jonsson   Moderators   -  Reputation: 3239

Like
1Likes
Like

Posted 06 March 2014 - 05:59 PM

Does it work if you compile directly with the makefile instead of using the Eclipse IDE?

 

What version of gnuc are you using with Eclipse?


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 07 March 2014 - 04:31 AM

I compiling lib using 'make' command from sdk/angelscript/projects/gnuc

Then I copy angelscript.a to project. 

If eclipse use default installed g++ then It use :

g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
If not, If you say how to check of gnuc version of eclipse I'll say.
Sorry,I'm novice in C/C++,so I can do something wrong.
About makefile: I thought eclipse building makefile automatially. But I'll try to build something including angelscript.a using makefile and write here results


#6 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 07 March 2014 - 12:18 PM

Hadn't learned makefiles yet, but when I compile simple c++ file that includes "angelscript.h" with '-L. -langelscript' flags (angelscript.a in directory I compile from) it compiles and launches fine. I think it's problem with eclipse.



#7 Andreas Jonsson   Moderators   -  Reputation: 3239

Like
0Likes
Like

Posted 07 March 2014 - 04:12 PM

How do you link with the AngelScript library from the Eclipse project? Linking with the pthread library should be done the same way. The only difference is that the pthread library is a standard library that comes with the gnuc compiler, and is most likely installed in your standard OS directory where all ordinary shared libraries are.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#8 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 08 March 2014 - 11:12 AM

I link AS library by going into project properties -> C/C++ Build -> Settings -> Cross G++ Linker -> Libraries, then write angelscript in -l text field and setting path to project where libangelscript.a placed in -L text field.



#9 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 08 March 2014 - 11:26 AM

using namespace std;
#include <cstdio>
#include <string>
#include "angelscript.h"
#include "./scriptbuilder.h"

CScriptBuilder builder;
asIScriptEngine *engine;
string modules[1000];
int moduleslength = 0;
void MessageCallback(const asSMessageInfo *msg, void *param)
{
  const char *type = "ERR ";
  if( msg->type == asMSGTYPE_WARNING )
    type = "WARN";
  else if( msg->type == asMSGTYPE_INFORMATION )
    type = "INFO";
  printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}
//utils----------
bool check(int in);
//---------------
bool as_register();
bool as_compile(string path,string modulename);
bool as_init()
{
	engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	int r = engine->SetMessageCallback(asFUNCTION(MessageCallback),0,asCALL_CDECL);
	if (r>=0) return false;
//	RegisterStdString(engine);
	if (as_register())
		{
		return false;
		}
	return true;
}

bool as_compile (string path,string modulename)
{
	for(int i = 0;i<moduleslength;i++)
	{
		if(modules[i]==modulename)
		{
			printf("FFFFFUUUUUU. Module name already exist");
			return false;
		}
	}

	// The CScriptBuilder helper is an add-on that loads the file,
	// performs a pre-processing pass if necessary, and then tells
	// the engine to build a script module.
	int r = builder.StartNewModule(engine, modulename.c_str());
	if( r < 0 )
	{
	  // If the code fails here it is usually because there
	  // is no more memory to allocate the module
	  printf("Unrecoverable error while starting a new module.\n");
	  return false;
	}
	r = builder.AddSectionFromFile(path.c_str());
	if( r < 0 )
	{
	  // The builder wasn't able to load the file. Maybe the file
	  // has been removed, or the wrong name was given, or some
	  // preprocessing commands are incorrectly written.
	  printf("Please correct the errors in the script and try again.\n");
	  return false;
	}
	r = builder.BuildModule();
	if( r < 0 )
	{
	  // An error occurred. Instruct the script writer to fix the
	  // compilation errors that were listed in the output stream.
	  printf("Please correct the errors in the script and try again.\n");
	  return false;
	}
	modules[moduleslength]=modulename;
	moduleslength++;
	return true;
}

//Here goes function declaration prototypes stuff
void print(const string &in);
//-----------------------------------------------
bool as_register()
{
	int r = engine->RegisterGlobalFunction("void print(const string &in)",asFUNCTION(print), asCALL_CDECL);
	if (check(r)) return false;
	return true;
}
bool check(int in)
{
	return in >= 0;
}
bool runmodule(string modulename)
{
	// Find the function that is to be called.
	asIScriptModule *mod = engine->GetModule(modulename.c_str());
	asIScriptFunction *func = mod->GetFunctionByDecl("void main()");
	if( func == 0 )
	{
	  // The function couldn't be found. Instruct the script writer
	  // to include the expected function in the script.
	  printf("The script must have the function 'void main()'. Please add it and try again.\n");
	  return false;
	}
	// Create our context, prepare it, and then execute
	asIScriptContext *ctx = engine->CreateContext();
	ctx->Prepare(func);
	int r = ctx->Execute();
	if( r != asEXECUTION_FINISHED )
	{
	  // The execution didn't complete as expected. Determine what happened.
	  if( r == asEXECUTION_EXCEPTION )
	  {
	    // An exception occurred, let the script writer know what happened so it can be corrected.
	    printf("An exception '%s' occurred. Please correct the code and try again.\n", ctx->GetExceptionString());
	  }
	}
	return true;
}

int main()
{
printf("OK");
}


That's code I using.

But when I compile it using :

g++ test.cpp scriptbuilder.cpp scriptbuilder.h  -L. -langelscript -lpthread -o test

It returns :

 

/tmp/ccTRpvvj.o: In function `as_register()':
test.cpp:(.text+0x28d): undefined reference to `print(std::string const&)'
collect2: error: ld returned 1 exit status
 
Can anybody say what I do wrong?
Used code from 'Your first script' and changed it a bit.
Also, theres scriptbuilder.cpp and scriptbuilder.h and angelscript.a in catalog I execute command from

Edited by jammer312, 08 March 2014 - 11:27 AM.


#10 Andreas Jonsson   Moderators   -  Reputation: 3239

Like
1Likes
Like

Posted 08 March 2014 - 11:43 AM

You haven't implemented the void print(const std::string &)' function that you declare on line 83.

 

Regards,

Andreas


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#11 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 08 March 2014 - 12:19 PM

Thanks, I think it was deleted accidentally. Any thoughts about eclipse linking problem? 



#12 Andreas Jonsson   Moderators   -  Reputation: 3239

Like
0Likes
Like

Posted 08 March 2014 - 12:32 PM

Unfortunately I don't know anything about Eclipse. If you've already tried adding pthread the same way you add angelscript itself then I have no clue what else to try.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#13 jammer312   Members   -  Reputation: 113

Like
0Likes
Like

Posted 08 March 2014 - 12:34 PM

Ok. I'll learn makefiles then(because it compiles fine with G++ without eclipse)

Thanks for help.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS