Hello, I'm new to C++ and of course to the V8 engine, too. I would like to create an javascript service to send request to a server (something similar accessing an SQL Server). My main application code is executing without problems (i included V8 as a static library), but every time I try accessing an plugin in an shared library, it produces many errors like " symbol lookup error: ./libs/testplugin.so: undefined symbol: _ZN2v816FunctionTemplate16InstanceTemplateEv". I have really no idea how to solve this errors. I have already searched solutions for this, but no one worked for me. I assume that my program isn't able to find the matching v8 symbols. I have already added -Wl,-export-dynamic to the linker options, but it still is not loading the library at runtime.
I would be very grateful for any kind of advise or solution on this problem
On Thu, Sep 27, 2012 at 1:58 PM, Moritz Willig <moritz.wil...@gmail.com> wrote:
> Hello,
> I'm new to C++ and of course to the V8 engine, too. I would like to create
> an javascript service to send request to a server (something similar
> accessing an SQL Server). My main application code is executing without
> problems (i included V8 as a static library), but every time I try accessing
> an plugin in an shared library, it produces many errors like " symbol lookup
> error: ./libs/testplugin.so: undefined symbol:
> _ZN2v816FunctionTemplate16InstanceTemplateEv". I have really no idea how to
> solve this errors. I have already searched solutions for this, but no one
> worked for me. I assume that my program isn't able to find the matching v8
> symbols. I have already added -Wl,-export-dynamic to the linker options, but
> it still is not loading the library at runtime.
> I would be very grateful for any kind of advise or solution on this problem
Hi CodeJunkie, i know NodeJS and have already build some Projects with it. But I want to learn how to solve this problem this in general. As far as i see does NodeJS also provide Plugins but they have to be linked statically into the program (or have to be written in JS itself). Maybe I switch to NodeJS later but at the moment i would like to learn how to do this on my own.
Am Donnerstag, 27. September 2012 23:21:18 UTC+2 schrieb CodeJunkie:
> On Thu, Sep 27, 2012 at 1:58 PM, Moritz Willig <moritz...@gmail.com<javascript:>> > wrote: > > Hello, > > I'm new to C++ and of course to the V8 engine, too. I would like to > create > > an javascript service to send request to a server (something similar > > accessing an SQL Server). My main application code is executing without > > problems (i included V8 as a static library), but every time I try > accessing > > an plugin in an shared library, it produces many errors like " symbol > lookup > > error: ./libs/testplugin.so: undefined symbol: > > _ZN2v816FunctionTemplate16InstanceTemplateEv". I have really no idea how > to > > solve this errors. I have already searched solutions for this, but no > one > > worked for me. I assume that my program isn't able to find the matching > v8 > > symbols. I have already added -Wl,-export-dynamic to the linker options, > but > > it still is not loading the library at runtime.
> > I would be very grateful for any kind of advise or solution on this > problem
On Fri, Sep 28, 2012 at 7:07 AM, Moritz Willig <moritz.wil...@gmail.com>wrote:
> i know NodeJS and have already build some Projects with it. But I want to
> learn how to solve this problem this in general. As far as i see does
> NodeJS also provide Plugins but they have to be linked statically into the
> program (or have to be written in JS itself).
FWIW: there is no "in general" solution to this problem from a v8
perspective because v8 does not define any sort of native-side plugin
interface and the behaviour of DLLs is unspecified by the C++ standard.
Both SilkJS and v8cgi support loading of dynamic libraries. It is tricky to get working.
To the best of my knowledge:
The problem is you have v8 as a static library. It needs to be a shared one and the shared library (testplugin) needs to be linked against libv8.so and every other library it calls.
> Hi CodeJunkie,
> i know NodeJS and have already build some Projects with it. But I want to learn how to solve this problem this in general. As far as i see does NodeJS also provide Plugins but they have to be linked statically into the program (or have to be written in JS itself).
> Maybe I switch to NodeJS later but at the moment i would like to learn how to do this on my own.
> Am Donnerstag, 27. September 2012 23:21:18 UTC+2 schrieb CodeJunkie:
> http://nodejs.org/
> On Thu, Sep 27, 2012 at 1:58 PM, Moritz Willig <moritz...@gmail.com> wrote: > > Hello, > > I'm new to C++ and of course to the V8 engine, too. I would like to create > > an javascript service to send request to a server (something similar > > accessing an SQL Server). My main application code is executing without > > problems (i included V8 as a static library), but every time I try accessing > > an plugin in an shared library, it produces many errors like " symbol lookup > > error: ./libs/testplugin.so: undefined symbol: > > _ZN2v816FunctionTemplate16InstanceTemplateEv". I have really no idea how to > > solve this errors. I have already searched solutions for this, but no one > > worked for me. I assume that my program isn't able to find the matching v8 > > symbols. I have already added -Wl,-export-dynamic to the linker options, but > > it still is not loading the library at runtime.
> > I would be very grateful for any kind of advise or solution on this problem
On Fri, Sep 28, 2012 at 2:36 PM, Michael Schwartz <myk...@gmail.com> wrote:
> The problem is you have v8 as a static library. It needs to be a shared
> one and the shared library (testplugin) needs to be linked against libv8.so
> and every other library it calls.
The issue is you have a .so that's getting loaded via dlopen(). That .so needs to call functions in the v8 library that is statically linked into the main program.
Static linking does not, at all, guarantee all of the functions of the static library are present in the main program binary to be called by some undeterminable .so loaded via dlopen().
It's even problematic for the main program to provide a function, foo(), and call that from a .so.
I mentioned v8cgi because I know Ondras fairly well and he ran into these same issues and had to ask on mailing lists for help with the solution. It should be easy, but it isn't.
On Sep 28, 2012, at 6:21 AM, Stephan Beal <sgb...@googlemail.com> wrote:
> On Fri, Sep 28, 2012 at 2:36 PM, Michael Schwartz <myk...@gmail.com> wrote:
> The problem is you have v8 as a static library. It needs to be a shared one and the shared library (testplugin) needs to be linked against libv8.so and every other library it calls.
On Fri, Sep 28, 2012 at 3:39 PM, Michael Schwartz <myk...@gmail.com> wrote:
> I didn't see anything useful at the link.
It explains, for example, why static libs are sometimes problematic in
conjunction with C++ templates and plugins (because unreferenced symbols do
not get linked in to the client).
> The issue is you have a .so that's getting loaded via dlopen(). That .so
> needs to call functions in the v8 library that is statically linked into
> the main program.
For example. And if those do not get referenced from client code then they
don't (or might not) get linked in.
I meant no offense. I just don't see any command line examples in it that would help with the problem at hand (his plugin not finding symbols in main with statically linked v8 library).
I also see no discussion of the loaded .so making calls to functions defined in the main program.
Peace
On Sep 28, 2012, at 6:44 AM, Stephan Beal <sgb...@googlemail.com> wrote:
> On Fri, Sep 28, 2012 at 3:39 PM, Michael Schwartz <myk...@gmail.com> wrote:
> I didn't see anything useful at the link.
> It explains, for example, why static libs are sometimes problematic in conjunction with C++ templates and plugins (because unreferenced symbols do not get linked in to the client).
> The issue is you have a .so that's getting loaded via dlopen(). That .so needs to call functions in the v8 library that is statically linked into the main program.
> For example. And if those do not get referenced from client code then they don't (or might not) get linked in.
Hi, i have read through the links and projects code you mentioned and also tried to link v8 dynamically (which fails at the moment). I'm not 100% percent sure but via "nm neptunjs | c++filt | grep v8::Throw" I looked up the object definitions in my program and found "0805bb00 t v8::ThrowException(v8::Handle<v8::Value>)" which is not found on dynamic linking of the plugin. Is there any compiler/linker switch I overlooked to make this definition public to the plugin or something else to get this working? At the moment I'm trying to load my plugins with this code:
NativeClass* loadNMLib(string path) { void* handle = dlopen(path.c_str(), RTLD_NOW|RTLD_GLOBAL); //It already fails here because of "undefined symbols" if (handle==NULL) { cout<<"Error: "<<dlerror()<<endl; return NULL; }
> I meant no offense. I just don't see any command line examples in it that > would help with the problem at hand (his plugin not finding symbols in main > with statically linked v8 library).
> I also see no discussion of the loaded .so making calls to functions > defined in the main program.
> Peace
> On Sep 28, 2012, at 6:44 AM, Stephan Beal <sgb...@googlemail.com<javascript:>> > wrote:
> On Fri, Sep 28, 2012 at 3:39 PM, Michael Schwartz <myk...@gmail.com<javascript:> > > wrote:
>> I didn't see anything useful at the link.
> It explains, for example, why static libs are sometimes problematic in > conjunction with C++ templates and plugins (because unreferenced symbols do > not get linked in to the client).
>> The issue is you have a .so that's getting loaded via dlopen(). That .so >> needs to call functions in the v8 library that is statically linked into >> the main program.
> For example. And if those do not get referenced from client code then they > don't (or might not) get linked in.
On Fri, Sep 28, 2012 at 4:58 AM, Moritz Willig <moritz.wil...@gmail.com> wrote:
> Hello,
> I'm new to C++ and of course to the V8 engine, too. I would like to create
> an javascript service to send request to a server (something similar
> accessing an SQL Server). My main application code is executing without
> problems (i included V8 as a static library), but every time I try accessing
> an plugin in an shared library, it produces many errors like " symbol lookup
> error: ./libs/testplugin.so: undefined symbol:
> _ZN2v816FunctionTemplate16InstanceTemplateEv". I have really no idea how to
> solve this errors. I have already searched solutions for this, but no one
> worked for me. I assume that my program isn't able to find the matching v8
> symbols. I have already added -Wl,-export-dynamic to the linker options, but
> it still is not loading the library at runtime.
Since you mentioned '-Wl,-export-dynamic', I assume you're compiling
under Linux environment with GCC.
Genrally, if you link with static V8, a '-rdynamic' in ldflags would
do the job, if you still get symbol lookup errors, find if you have
'-fvisibility=hidden' and '-fvisibility-inlines-hidden' in your
cflags, which will hide all symbols.
Another reason for this error is those symbols are garbage collected
by compiler, see if you have ''-fdata-sections' and in cflags, and
'-Wl,--gc-sections' in ldflags.
Hi, I have looked into the makefiles (I'm using Netbeans for C++ to manage my project and create the makefiles) and searched for the flags you mentioned. I found out that it uses -O2 to compile but as far as I see that doesn't include on of this flags. Currently I compile and link with g++: main: compile: g++-4.6 -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/main.o src/main.cpp linking: g++-4.6 -o bin/neptunjs ${OBJECTFILES} -lpthread -ldl -rdynamic
shared library: compile: g++-4.6: -O2 -fPIC -MMD -MP -MF $@.d -o ${OBJECTDIR}/main.o main.cpp linking: g++-4.6 -shared -o libbasic.so -fPIC ${OBJECTFILES} I copied this code directly from the makefiles (and replaced some variables). I think if this isn't going to work I'm going back compiling the plugins directly into the program.
Am Samstag, 29. September 2012 04:30:56 UTC+2 schrieb Zhao Cheng:
> On Fri, Sep 28, 2012 at 4:58 AM, Moritz Willig <moritz...@gmail.com<javascript:>> > wrote: > > Hello, > > I'm new to C++ and of course to the V8 engine, too. I would like to > create > > an javascript service to send request to a server (something similar > > accessing an SQL Server). My main application code is executing without > > problems (i included V8 as a static library), but every time I try > accessing > > an plugin in an shared library, it produces many errors like " symbol > lookup > > error: ./libs/testplugin.so: undefined symbol: > > _ZN2v816FunctionTemplate16InstanceTemplateEv". I have really no idea how > to > > solve this errors. I have already searched solutions for this, but no > one > > worked for me. I assume that my program isn't able to find the matching > v8 > > symbols. I have already added -Wl,-export-dynamic to the linker options, > but > > it still is not loading the library at runtime.
> Since you mentioned '-Wl,-export-dynamic', I assume you're compiling > under Linux environment with GCC.
> Genrally, if you link with static V8, a '-rdynamic' in ldflags would > do the job, if you still get symbol lookup errors, find if you have > '-fvisibility=hidden' and '-fvisibility-inlines-hidden' in your > cflags, which will hide all symbols.
> Another reason for this error is those symbols are garbage collected > by compiler, see if you have ''-fdata-sections' and in cflags, and > '-Wl,--gc-sections' in ldflags.
> -- > Cheng > Intel Open Source Technology Center