Downloaded lua5_1_4_Sources.tar.gz and compiled liblua.a from source using TDM-GCC 4.5.1.
Everything compiled fine:
Linking ..
ar rcs liblua.a 5.1.4/src/lapi.o 5.1.4/src/lauxlib.o 5.1.4/src/lbaselib.o 5.1.4/src/lcode.o 5.1.4/src/ldblib.o 5.1.4/s rc/ldebug.o 5.1.4/src/ldo.o 5.1.4/src/ldump.o 5.1.4/src/lfunc.o 5.1.4/src/lgc.o 5.1.4/src/linit.o 5.1.4/src/liolib.o 5.1 .4/src/llex.o 5.1.4/src/lmathlib.o 5.1.4/src/lmem.o 5.1.4/src/loadlib.o 5.1.4/src/lobject.o 5.1.4/src/lopcodes.o 5.1.4/s rc/loslib.o 5.1.4/src/lparser.o 5.1.4/src/lstate.o 5.1.4/src/lstring.o 5.1.4/src/lstrlib.o 5.1.4/src/ltable.o 5.1.4/src/ ltablib.o 5.1.4/src/ltm.o 5.1.4/src/lua.o 5.1.4/src/luac.o 5.1.4/src/lundump.o 5.1.4/src/lvm.o 5.1.4/src/lzio.o 5.1.4/sr c/print.o 5.1.4/src/wmain.o
Compiled example source just fine:
http://pastebin.com/EGvMRjth
Tried to link:
Compiling..
g++ test.o -g -shared -Lshared/build/lua -llua -o libtest.so
test.o:test.cpp:(.text+0x15): undefined reference to `lua_tonumber(lua_State*, int)'
test.o:test.cpp:(.text+0x40): undefined reference to `lua_pushnumber(lua_State*, double)'
test.o:test.cpp:(.text+0x60): undefined reference to `lua_tonumber(lua_State*, int)'
test.o:test.cpp:(.text+0x8e): undefined reference to `lua_pushnumber(lua_State*, double)'
test.o:test.cpp:(.text+0xb6): undefined reference to `lua_pushcclosure(lua_State*, int (*)(lua_State*), int)'
test.o:test.cpp:(.text+0xd1): undefined reference to `lua_setfield(lua_State*, int, char const*)'
test.o:test.cpp:(.text+0xec): undefined reference to `lua_pushcclosure(lua_State*, int (*)(lua_State*), int)'
test.o:test.cpp:(.text+0x107): undefined reference to `lua_setfield(lua_State*, int, char const*)'
collect2: ld returned 1 exit status
I'm trying to follow the examples from here:
http://www.troubleshooters.com/codecorn/lua/lua_lua_calls_c.htm
As already discussed in the comments..
It seems you are compiling C++ and the Lua version you use is probably coded in C.
This means you need to include either the lua.hpp or if not available you need to include the libraries by using extern "C" like so:
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
};
Related
I have been struggling with Google protobufs lately. I have written a proto file called Button.proto.
Here are its contents:
syntax = "proto3";
package robotjoystick;
message Button {
string name = 1;
int32 id = 2;
uint32 state = 3;
}
I successfully compiled it with this command (with the $USER replaced with the acctual computer user):
protoc -I=/home/$USER/robotjoystickserver --cpp_out=/home/$USER/robotjoystickserver/proto_classes Button.proto
I am using protobuf version 3.7.1.
My *.cpp file is calleddumbprrotos.cpp and it is not compiling for some reason.
Here is my *.cpp file:
// Client side C/C++ program to demonstrate Socket programming
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
// This line was forgotten apparently - https://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found
#include <arpa/inet.h>
// This one was also forgotten - https://www.reddit.com/r/learnprogramming/comments/3tlii5/clinux_why_is_write_or_close_not_declared_in_this/
#include <unistd.h>
// This is SDL 2.0, the joystick control library
#include <SDL2/SDL.h>
// For Ctrl+C quitting
#include <signal.h>
// for std::end
//#include <iostream>
// Now we import the header files the protobuf compiler generated.
#include "proto_classes/Button.pb.h"
// This is a standard port
#define PORT 8080
//#include<iostream>
using namespace std;
// For the protobuf generated class.
using namespace robotjoystick;
int main(int argc, char const *argv[])
{
// https://developers.google.com/protocol-buffers/docs/cpptutorial
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
// Broken method 1
/*
const string thename = "blah";
robotjoystick::Button * thebutton;
thebutton = new Button();
thebutton->set_name("john");
thebutton->set_id(12);
*/
// Broken method 2
const string thename = "blah";
robotjoystick::Button thebutton;
thebutton.set_name("john");
thebutton.set_id(12);
return 0;
}
The 2 sections of code I have labeled are 2 versions of the same thing that I am trying to accomplish, but both are throwing the same type of error and I have no idea how to interpret it. What do I need to do to make this code compile?
I should also mention that I installed protobuf 3.7.1 right off of my home directory (meaning that the zip file for protobuf was extracted there and then installed there).
The error I get when I currently run the code, the exact way it is, I get this error:
Compiling dumbprotos.cpp
/tmp/cc7HHVQf.o: In function `google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]()':
dumbprotos.cpp:(.text._ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedB5cxx11Ev[_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedB5cxx11Ev]+0x5): undefined reference to `google::protobuf::internal::fixed_address_empty_string[abi:cxx11]'
/tmp/ccMdby3z.o: In function `AddDescriptors_Button_2eproto()':
Button.pb.cc:(.text+0xa6): undefined reference to `google::protobuf::internal::AddDescriptors(google::protobuf::internal::DescriptorTable*, void (* const*)(), int)'
/tmp/ccMdby3z.o: In function `robotjoystick::Button::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)':
Button.pb.cc:(.text+0x660): undefined reference to `google::protobuf::io::CodedInputStream::ReadTagFallback(unsigned int)'
Button.pb.cc:(.text+0x73f): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
/tmp/ccMdby3z.o: In function `robotjoystick::Button::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const':
Button.pb.cc:(.text+0x904): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
/tmp/ccMdby3z.o: In function `robotjoystick::Button::InternalSerializeWithCachedSizesToArray(unsigned char*) const':
Button.pb.cc:(.text+0xa98): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
/tmp/ccMdby3z.o: In function `robotjoystick::Button::GetMetadata() const':
Button.pb.cc:(.text+0x1386): undefined reference to `google::protobuf::internal::AssignDescriptors(google::protobuf::internal::AssignDescriptorsTable*)'
/tmp/ccMdby3z.o: In function `robotjoystick::Button* google::protobuf::Arena::CreateMaybeMessage<robotjoystick::Button>(google::protobuf::Arena*)':
Button.pb.cc:(.text+0x142e): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)'
Button.pb.cc:(.text+0x144b): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))'
/tmp/ccMdby3z.o: In function `google::protobuf::io::CodedInputStream::ReadVarint32(unsigned int*)':
Button.pb.cc:(.text._ZN6google8protobuf2io16CodedInputStream12ReadVarint32EPj[_ZN6google8protobuf2io16CodedInputStream12ReadVarint32EPj]+0x78): undefined reference to `google::protobuf::io::CodedInputStream::ReadVarint32Fallback(unsigned int)'
/tmp/ccMdby3z.o: In function `google::protobuf::Arena::AllocHook(std::type_info const*, unsigned long) const':
Button.pb.cc:(.text._ZNK6google8protobuf5Arena9AllocHookEPKSt9type_infom[_ZNK6google8protobuf5Arena9AllocHookEPKSt9type_infom]+0x3d): undefined reference to `google::protobuf::Arena::OnArenaAllocation(std::type_info const*, unsigned long) const'
/tmp/ccMdby3z.o: In function `google::protobuf::internal::ArenaStringPtr::CreateInstance(google::protobuf::Arena*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*)':
Button.pb.cc:(.text._ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x23e): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)'
Button.pb.cc:(.text._ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25b): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))'
/tmp/ccMdby3z.o: In function `google::protobuf::internal::InitSCC(google::protobuf::internal::SCCInfoBase*)':
Button.pb.cc:(.text._ZN6google8protobuf8internal7InitSCCEPNS1_11SCCInfoBaseE[_ZN6google8protobuf8internal7InitSCCEPNS1_11SCCInfoBaseE]+0x4d): undefined reference to `google::protobuf::internal::InitSCCImpl(google::protobuf::internal::SCCInfoBase*)'
/tmp/ccMdby3z.o: In function `google::protobuf::internal::OnShutdownDestroyMessage(void const*)':
Button.pb.cc:(.text._ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv[_ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv]+0x14): undefined reference to `google::protobuf::internal::DestroyMessage(void const*)'
Button.pb.cc:(.text._ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv[_ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv]+0x19): undefined reference to `google::protobuf::internal::OnShutdownRun(void (*)(void const*), void const*)'
/tmp/ccMdby3z.o: In function `google::protobuf::internal::InternalMetadataWithArena::default_instance()':
Button.pb.cc:(.text._ZN6google8protobuf8internal25InternalMetadataWithArena16default_instanceEv[_ZN6google8protobuf8internal25InternalMetadataWithArena16default_instanceEv]+0x5): undefined reference to `google::protobuf::UnknownFieldSet::default_instance()'
/tmp/ccMdby3z.o: In function `google::protobuf::internal::InternalMetadataWithArenaBase<google::protobuf::UnknownFieldSet, google::protobuf::internal::InternalMetadataWithArena>::mutable_unknown_fields_slow()':
Button.pb.cc:(.text._ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv[_ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv]+0x15c): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)'
Button.pb.cc:(.text._ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv[_ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv]+0x176): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))'
/tmp/ccMdby3z.o:(.rodata._ZTVN13robotjoystick6ButtonE[_ZTVN13robotjoystick6ButtonE]+0xb8): undefined reference to `google::protobuf::Message::SpaceUsedLong() const'
collect2: error: ld returned 1 exit status
When I compile the code wth the other broken scenario,
const string thename = "blah";
robotjoystick::Button * thebutton;
thebutton = new Button();
thebutton->set_name("john");
thebutton->set_id(12);
I get this error instead:
Compiling dumbprotos.cpp
/tmp/ccaCT7Iy.o: In function `google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]()':
dumbprotos.cpp:(.text._ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedB5cxx11Ev[_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedB5cxx11Ev]+0x5): undefined reference to `google::protobuf::internal::fixed_address_empty_string[abi:cxx11]'
/tmp/ccfmvBXP.o: In function `AddDescriptors_Button_2eproto()':
Button.pb.cc:(.text+0xa6): undefined reference to `google::protobuf::internal::AddDescriptors(google::protobuf::internal::DescriptorTable*, void (* const*)(), int)'
/tmp/ccfmvBXP.o: In function `robotjoystick::Button::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)':
Button.pb.cc:(.text+0x660): undefined reference to `google::protobuf::io::CodedInputStream::ReadTagFallback(unsigned int)'
Button.pb.cc:(.text+0x73f): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
/tmp/ccfmvBXP.o: In function `robotjoystick::Button::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const':
Button.pb.cc:(.text+0x904): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
/tmp/ccfmvBXP.o: In function `robotjoystick::Button::InternalSerializeWithCachedSizesToArray(unsigned char*) const':
Button.pb.cc:(.text+0xa98): undefined reference to `google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)'
/tmp/ccfmvBXP.o: In function `robotjoystick::Button::GetMetadata() const':
Button.pb.cc:(.text+0x1386): undefined reference to `google::protobuf::internal::AssignDescriptors(google::protobuf::internal::AssignDescriptorsTable*)'
/tmp/ccfmvBXP.o: In function `robotjoystick::Button* google::protobuf::Arena::CreateMaybeMessage<robotjoystick::Button>(google::protobuf::Arena*)':
Button.pb.cc:(.text+0x142e): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)'
Button.pb.cc:(.text+0x144b): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))'
/tmp/ccfmvBXP.o: In function `google::protobuf::io::CodedInputStream::ReadVarint32(unsigned int*)':
Button.pb.cc:(.text._ZN6google8protobuf2io16CodedInputStream12ReadVarint32EPj[_ZN6google8protobuf2io16CodedInputStream12ReadVarint32EPj]+0x78): undefined reference to `google::protobuf::io::CodedInputStream::ReadVarint32Fallback(unsigned int)'
/tmp/ccfmvBXP.o: In function `google::protobuf::Arena::AllocHook(std::type_info const*, unsigned long) const':
Button.pb.cc:(.text._ZNK6google8protobuf5Arena9AllocHookEPKSt9type_infom[_ZNK6google8protobuf5Arena9AllocHookEPKSt9type_infom]+0x3d): undefined reference to `google::protobuf::Arena::OnArenaAllocation(std::type_info const*, unsigned long) const'
/tmp/ccfmvBXP.o: In function `google::protobuf::internal::ArenaStringPtr::CreateInstance(google::protobuf::Arena*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*)':
Button.pb.cc:(.text._ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x23e): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)'
Button.pb.cc:(.text._ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN6google8protobuf8internal14ArenaStringPtr14CreateInstanceEPNS0_5ArenaEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25b): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))'
/tmp/ccfmvBXP.o: In function `google::protobuf::internal::InitSCC(google::protobuf::internal::SCCInfoBase*)':
Button.pb.cc:(.text._ZN6google8protobuf8internal7InitSCCEPNS1_11SCCInfoBaseE[_ZN6google8protobuf8internal7InitSCCEPNS1_11SCCInfoBaseE]+0x4d): undefined reference to `google::protobuf::internal::InitSCCImpl(google::protobuf::internal::SCCInfoBase*)'
/tmp/ccfmvBXP.o: In function `google::protobuf::internal::OnShutdownDestroyMessage(void const*)':
Button.pb.cc:(.text._ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv[_ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv]+0x14): undefined reference to `google::protobuf::internal::DestroyMessage(void const*)'
Button.pb.cc:(.text._ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv[_ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv]+0x19): undefined reference to `google::protobuf::internal::OnShutdownRun(void (*)(void const*), void const*)'
/tmp/ccfmvBXP.o: In function `google::protobuf::internal::InternalMetadataWithArena::default_instance()':
Button.pb.cc:(.text._ZN6google8protobuf8internal25InternalMetadataWithArena16default_instanceEv[_ZN6google8protobuf8internal25InternalMetadataWithArena16default_instanceEv]+0x5): undefined reference to `google::protobuf::UnknownFieldSet::default_instance()'
/tmp/ccfmvBXP.o: In function `google::protobuf::internal::InternalMetadataWithArenaBase<google::protobuf::UnknownFieldSet, google::protobuf::internal::InternalMetadataWithArena>::mutable_unknown_fields_slow()':
Button.pb.cc:(.text._ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv[_ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv]+0x15c): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAligned(unsigned long)'
Button.pb.cc:(.text._ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv[_ZN6google8protobuf8internal29InternalMetadataWithArenaBaseINS0_15UnknownFieldSetENS1_25InternalMetadataWithArenaEE27mutable_unknown_fields_slowEv]+0x176): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))'
/tmp/ccfmvBXP.o:(.rodata._ZTVN13robotjoystick6ButtonE[_ZTVN13robotjoystick6ButtonE]+0xb8): undefined reference to `google::protobuf::Message::SpaceUsedLong() const'
collect2: error: ld returned 1 exit status
This is the script I am using to compile the code:
#!/bin/sh
echo "Compiling dumbprotos.cpp"
echo ""
g++ dumbprotos.cpp proto_classes/Button.pb.cc -o ./pleasework -std=c++11 -lSDL2 -lprotobuf
I think that is everything I need to show you guys. Did I miss anything? What do I need to do to make my *.cpp code compile?
I am on Ubuntu 16.04.
After thinking about the comment provided by #goduk, I thought I should look further into the linking library issue and find the files I need to source. It turns out that I was not linking to any specific location.
I decided to look through the docs under protobuf-3.7.1/src/README.md to explore further to find the .../lib/ directory. After re-reading those docs, a specific section caught my eye.
To compile a package that uses Protocol Buffers, you need to pass
various flags to your compiler and linker. As of version 2.2.0,
Protocol Buffers integrates with pkg-config to manage this. If you
have pkg-config installed, then you can invoke it to get a list of
flags like so:
pkg-config --cflags protobuf # print compiler flags
pkg-config --libs protobuf # print linker flags
pkg-config --cflags --libs protobuf # print both
For example:
c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`
On my laptop, the command pkg-config --cflags --libs protobuf returns -pthread -I/usr/local/include -L/usr/local/lib -lprotobuf -pthread.
Instead of trying to determine the correct compiling flags, I simply needed to call the required flags using pkg-config --cflags --libs protobuf at the end.
I had never heard of pkg-config before, but this solved all of my problems.
The final bash script line is now this:
g++ dumbprotos.cpp proto_classes/Button.pb.cc -o ./pleasework -std=c++11 -lSDL2 `pkg-config --cflags --libs protobuf`
Thanks for the help.
(This is a linker type issue.)
I should also mention that, if the protobuf object contains other protobuf objects, you have to include those in the command line call:
g++ my_program.cc my_proto_imported.pb.cc my_proto_containing.pb.cc `pkg-config --cflags --libs protobuf`
Meaning that my_proto_imported.pb.cc is a protobuf imported and used in my_proto_contained.pb.cc.
I'm trying to compile a large code with gcc(5.3), which was compiled with icpc before.(I have mkl libraries loaded) Compilation was successful but with the following warning:
warning: narrowing conversion of 'p_jShell->simint_shell::nprim' from 'int' to
'unsigned int' inside { } [-Wnarrowing]
{ p_iShell->nprim, p_jShell->nprim };
But I get run time errors 'undefined referece' to __intel_ssse3_rep_memcpy, _mm_free,_mm_malloc,__svml_pow4,_intel_fast_memset etc..
In function `simgms_oei(std::vector<std::vector<simint_shell, std::allocator<simint_shell> >, std::allocator<std::vector<simint_shell, std::allocator<simint_shell> > > >&, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&, std::vector<std::vector<unsigned int, std::allocator<unsigned int> >, std::allocator<std::vector<unsigned int, std::allocator<unsigned int> > > >&, unsigned int, AtomData&)':
/home/..../simgms_oei.cpp:126: undefined reference to `oed__memory_ovl_batch_'
..
..
In function `simint_copy_shell':
shell.c:(.text+0x126): undefined reference to `__intel_ssse3_rep_memcpy'
.
shell.c:(.text+0x32fe): undefined reference to `_mm_free'
shell.c:(.text+0x335c): undefined reference to `_mm_malloc'
.
ostei_p_s_f_p.c:(.text+0x27f): undefined reference to `_intel_fast_memset'
.
..
..
I suspect this could be from a linking problem. I linked gcc lib directory but I'm not sure what libraries I need to have here. Any suggestions? Anyone see what I'm doing wrong here? Thanks!
gcc -mavx -g -O -O1 -std=c++11 -L/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/lib64 -libstdc -libsupc++ -libtsan -libubsan -libvtv -libquadmath -libgcc_s -libgcj -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -libmkl_mc -libmkl_sequential -libmkl_gf_ilp64 -libmkl_avx -libmkl_lapack95_lp64 -libmkl_intel_lp64 -libmkl_core -lmkl_gnu_thread -I/opt/intel/composer_xe_2013.5.192/mkl/include -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -I/***/simint/include -DDEBUG -DMKL_ILP64 -MMD -MP -MF"simgms_init.d" -MT"simgms_init.d" -c -o "simgms_init.o" "../simgms_init.cpp"
I tried found the library all the cpp files(simgms_oei.cpp etc..) were compiled into and tried the nm commands below:
>> nm libsimint.a |grep __intel_ssse3_rep_memcpy
U __intel_ssse3_rep_memcpy
>> nm libsimint.a |grep simint_copy_shell
0000000000000090 T simint_copy_shell
When you lookup U and T it meant the following:
simint_copy_shell function is mentioned in code but __intel_ssse3_rep_memcpy is not defined in some other libray our libsimint is compiled with
The conclusion is that the library is compiled with icpc and I had to recompile it separately with gcc before linking it in the above step.
Adding Wl, command to the linker script like this:
--Wl,--start-group -L/opt/share... -lsomelib -lsomeotherlib -L/xxx/...-lsomelib -Wl,--end-group
Got rid of the other errors I had due to linking order.
Well, it's a very strange error I met.
When I try to compile my program with the fftw library by the command:
g++ -std=c++11 -o main main.cpp BFSCcommandlineParser.cpp BFSCframe.cpp BFSCgeometry.cpp ImageIO.cpp -lfftw3 -lm
... I get this:
/tmp/cczUuTb0.o: In function `fftw_prog::fftw_prog(char const*)':
main.cpp:(.text._ZN9fftw_progC2EPKc[_ZN9fftw_progC5EPKc]+0x5c): undefined reference to `fftwf_import_wisdom_from_file'
/tmp/cczUuTb0.o: In function `fftw_prog::~fftw_prog()':
main.cpp:(.text._ZN9fftw_progD2Ev[_ZN9fftw_progD5Ev]+0x31): undefined reference to `fftwf_export_wisdom_to_file'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::fft(tensor<int, 2ul>, bool)':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEEC2E6tensorIiLm2EEb[_ZN3fftILi2EfSt7complexIfEEC5E6tensorIiLm2EEb]+0xcf): undefined reference to `fftwf_plan_dft_r2c'
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEEC2E6tensorIiLm2EEb[_ZN3fftILi2EfSt7complexIfEEC5E6tensorIiLm2EEb]+0x111): undefined reference to `fftwf_plan_dft_c2r'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::~fft()':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEED2Ev[_ZN3fftILi2EfSt7complexIfEED5Ev]+0x25): undefined reference to `fftwf_free'
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEED2Ev[_ZN3fftILi2EfSt7complexIfEED5Ev]+0x35): undefined reference to `fftwf_destroy_plan'
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEED2Ev[_ZN3fftILi2EfSt7complexIfEED5Ev]+0x45): undefined reference to `fftwf_destroy_plan'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::r2F()':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEE3r2FEv[_ZN3fftILi2EfSt7complexIfEE3r2FEv]+0x25): undefined reference to `fftwf_execute'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::F2r()':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEE3F2rEv[_ZN3fftILi2EfSt7complexIfEE3F2rEv]+0x35): undefined reference to `fftwf_execute'
collect2: error: ld returned 1 exit status
I thought it could be a problem of fftw itself, so I tested the library with a proram, and it worked. That means that it's not so.
The following code is a template from my file which is the only one in my project that uses fftw.
template <int N, typename rT, typename FT>
inline fft<N,rT,FT>::~fft() {
if (data != 0) {
if (Precision<rT>::IsFloat) {
fftwf_free((fftwf_complex *)data);
fftwf_destroy_plan((fftwf_plan_s*) r2Fplan);
fftwf_destroy_plan((fftwf_plan_s*) F2rplan);
}
else {
fftw_free((fftw_complex *)data);
fftw_destroy_plan((fftw_plan_s*) r2Fplan);
fftw_destroy_plan((fftw_plan_s*) F2rplan);
}
}
}
For single precision (float) you need to link the libfftwf library, for double precision (double) you need the libfftw library. I would guess you are just linking the latter and not the former. For gcc et al the command line needs to contain -lfftw3 -lfftw3f if you want both double and single precision support.
I'm trying to develop a packet analyzer with CUDA support for pattern matching. I'm using GTK+ for GUI creation but I am not able to compile the GUI file together with the cuda files. How to write makefile for this case?
The project is having two parts: 1. Analyzer 2. GUI
Analyzer consists of many .c,.h files and one .cu file.
GUI part has only one file gui.c
I have included packet_analyzer.h in gui.c.
I tried the following makefile
all: guitest
guitest: gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gcc -lpcap -lpthread `pkg-config --cflags --libs gtk+-2.0` gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gui.o: gui.c
gcc -lpcap -lpthread -c `pkg-config --cflags --libs gtk+-2.0` gui.c
list.o : list.c
gcc -c list.c
queue.o : queue.c
gcc -c queue.c
Word.o : Word.c Word.h
gcc -c Word.c
dictionary.o : dictionary.c
gcc -c dictionary.c
rule.o : rule.c rule.h
gcc -c rule.c rule.h
packet_capturer.o : packet_capturer.c
gcc -lpcap -lpthread -c packet_capturer.c
aho-corasick.o : aho-corasick.c
gcc -lpcap -lpthread -c aho-corasick.c
aho-corasick_cuda.o : aho-corasick_cuda.cu
nvcc -lpcap -lpthread -c aho-corasick_cuda.cu
packet_analyzer.o : packet_analyzer.c
gcc -lpcap -lpthread -c packet_analyzer.c
clean:
rm -rf *o guitest
i end up with the following errors:
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x37): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x86): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xac): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xd5): undefined reference to `cudaMalloc'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xfb): more undefined references to `cudaMalloc' follow
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x132): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x166): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x19d): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x1d1): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x208): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x23c): more undefined references to `cudaMemcpy' follow
aho-corasick_cuda.o: In function `transfer_packets_from_hosttodevice(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x3b1): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x519): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x52b): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x53d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x56b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x58b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5ab): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o: In function `analyze_packets(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x663): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x683): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x6dd): undefined reference to `cudaConfigureCall'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x777): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x78a): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7d5): undefined reference to `Queue_enqueue(Queue*, void*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7f3): undefined reference to `cudaFree'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x802): undefined reference to `cudaFree'
aho-corasick_cuda.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x824): undefined reference to `__cudaUnregisterFatBinary'
aho-corasick_cuda.o: In function `__device_stub__Z14AC_search_CudaPiS_S_S_S_S_S_S_PhiS_(int*, int*, int*, int*, int*, int*, int*, int*, unsigned char*, int, int*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x85c): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x87f): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8a2): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8c5): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8e8): undefined reference to `cudaSetupArgument'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x90b): more undefined references to `cudaSetupArgument' follow
aho-corasick_cuda.o: In function `__sti____cudaRegisterAll_52_tmpxft_00001608_00000000_4_aho_corasick_cuda_cpp1_ii_9958a654()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xa82): undefined reference to `__cudaRegisterFatBinary'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xae3): undefined reference to `__cudaRegisterFunction'
aho-corasick_cuda.o: In function `cudaError cudaLaunch<char>(char*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to `cudaLaunch'
aho-corasick_cuda.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [guitest] Error 1
You need to link with the CUDA runtime library. Add -lcudart to your link command (and CUDA lib path if necessary).
It's the nvcc -lpcap -lpthread $(ANALYZER) -o packet_analyzer.o line that's failing, right? With the -o option, you're telling it to build a complete executable, not just the object files. It needs a main function to do that, which I presume you don't have in any of the $(ANALYZER) files. Instead, try compiling all the sources with the -c flag (like you've done with gcc for gui.c), and then wrap it all together and link it with the other gcc command.
Does anyone know of a language engine (compiler or interpreter, AST, syntax, and basic semantics) but with NO standard library (hopefully not even integers or arithmetic). Is there such a thing? I'd want to be able to implement the standard library in C++. Does such a thing exist?
GCC (and I'm pretty sure a lot of other compilers) lets you build your code without the standard headers and/or libraries, with the -nostdinc (also -nostdinc++ for C++) and -nostdlib flags.
For example:
$ cat t.cpp
#include <iostream>
int main()
{
std::cout << "ouch" << std::endl;
}
$ g++ -nostdinc t.cpp # Failed compilation
t.cpp:1:20: error: no include path in which to search for iostream
t.cpp: In function ‘int main()’:
t.cpp:5:5: error: ‘cout’ is not a member of ‘std’
t.cpp:5:28: error: ‘endl’ is not a member of ‘std’
$ g++ -nostdinc++ t.cpp # Failed compilation
t.cpp:1:20: fatal error: iostream: No such file or directory
compilation terminated.
$ g++ -nostdlib t.cpp # Compiles, but fails to link
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400158
/tmp/ccPPO3l6.o: In function `main':
t.cpp:(.text+0xa): undefined reference to `std::cout'
t.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
t.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
t.cpp:(.text+0x1c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccPPO3l6.o: In function `__static_initialization_and_destruction_0(int, int)':
t.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
t.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()'
t.cpp:(.text+0x54): undefined reference to `__dso_handle'
t.cpp:(.text+0x61): undefined reference to `__cxa_atexit'
collect2: ld returned 1 exit status
This is used for building things like kernel code that can't use the C library.
Good luck with implementing a standard library, that's an enormous task.