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.
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.
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"
};
I'm attempting to follow the steps on http://llvm.org/docs/tutorial/LangImpl3.html to build the example.
based on
Building llvm examples
#error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
Why am I getting "undefined reference to `dladdr'" even with -ldl for this simple program?
I've ended up with the command
clang++ -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -std=c++11 -g -O3 toy.cpp `llvm-config --libs core --cppflags --ldflags` -o toy
which is giving
/usr/local/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::MutexImpl(bool)':
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:53: undefined reference to `pthread_mutexattr_init'
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:59: undefined reference to `pthread_mutexattr_settype'
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:67: undefined reference to `pthread_mutexattr_destroy'
/usr/local/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:109: undefined reference to `pthread_mutex_trylock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::RWMutexImpl()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:59: undefined reference to `pthread_rwlock_init'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::~RWMutexImpl()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:72: undefined reference to `pthread_rwlock_destroy'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_acquire()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:82: undefined reference to `pthread_rwlock_rdlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_release()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:92: undefined reference to `pthread_rwlock_unlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_acquire()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:102: undefined reference to `pthread_rwlock_wrlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_release()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:112: undefined reference to `pthread_rwlock_unlock'
/usr/local/lib/libLLVMSupport.a(Signals.o): In function `llvm::sys::PrintStackTrace(_IO_FILE*)':
/home/abdev/llvmHome/llvm/lib/Support/Unix/Signals.inc:278: undefined reference to `dladdr'
/home/abdev/llvmHome/llvm/lib/Support/Unix/Signals.inc:290: undefined reference to `dladdr'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::ThreadLocalImpl()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:56: undefined reference to `pthread_key_create'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::~ThreadLocalImpl()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:63: undefined reference to `pthread_key_delete'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::setInstance(void const*)':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:70: undefined reference to `pthread_setspecific'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::getInstance()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:77: undefined reference to `pthread_getspecific'
/usr/local/lib/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:91: undefined reference to `pthread_attr_setstacksize'
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:96: undefined reference to `pthread_create'
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:100: undefined reference to `pthread_join'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Am I missing a library, or is some of the order incorrect?
I believe you need to link with -lpthread or just -pthread
I'm using GCC (CygWin) cross-compiling targeting an Arm7 processor. the problem is none of the standard library functions are available for my program. as I understand it, libc.a is the library i should be using. strangely, this file has been copied to the application source directory.
I would've thought if I did the following, I should be able to use these functions:
have included (enclosed in <>) string.h and stdlib.h in my LCD.c file
mention libc.a to the linker
During make, here's what it says:
$ make
.compiling
..linking
arm-elf-ld -v -Map main.map -nostartfiles -T simple.cmd -o main.out start.o ivt.
o main.o libc.a LCD.o
GNU ld version 2.14 20030612
LCD.o(.text+0x75c): In function `LCD_DispSmallDigits':
: undefined reference to `strlen'
LCD.o(.text+0x22d4): In function `LCD_DispSelMsgAt':
: undefined reference to `malloc'
LCD.o(.text+0x22e0): In function `LCD_DispSelMsgAt':
: undefined reference to `strcpy'
LCD.o(.text+0x2308): In function `LCD_DispSelMsgAt':
: undefined reference to `free'
LCD.o(.text+0x2358): In function `LCD_DispNumMsgAt':
: undefined reference to `malloc'
LCD.o(.text+0x2368): In function `LCD_DispNumMsgAt':
: undefined reference to `sprintf'
LCD.o(.text+0x2384): In function `LCD_DispNumMsgAt':
: undefined reference to `free'
the code I'm using is quite mundane:
void LCD_DispSelMsgAt(int iRow, int iCol, int bSelected, char* s)
{
int i;
char* sBuffer = (char*) malloc(100);
strcpy(sBuffer, s);
if (bSelected)
for (i=0; i<strlen(sBuffer); i++)
if ((*(sBuffer + i)>='a') && (*(sBuffer + i)<='z'))
*(sBuffer + i) = (*(sBuffer + i)) - 0x20;
LCD_DispMsgAt(iRow, iCol, sBuffer);
free(sBuffer);
}
how can I get access to those standard routines?
thank you!
PS: it seems to me I'm having quite a "general" problem so what I'm about to say is not central to this question but i'll mention it anyway...
I noticed something that specifically relates to strlen( ). the prototype for strlen( ) has the parameter as "const char* s". it seems then it works fine with:
i = strlen("abc")
but not in the code sample routine shown above. that wouldn't be a very helpful library routine that can't be used as strlen(char* s).
reply to #n.m.:
adding /gnude/arm-elf/lib/libc.a to the linker command line introduced a "thousand" errors.
$ make
..linking
arm-elf-ld -v -Map main.map -nostartfiles -T LinkerScript.cmd -L /gnude/arm-elf/
lib -o main.out start.o ivt.o main.o LCD.o /gnude/arm-elf/lib/libc.a
GNU ld version 2.14 20030612
/gnude/arm-elf/lib/libc.a(syscalls.o)(.text+0x714): In function `_sbrk':
: undefined reference to `end'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x8c0): In function `_vfprintf_r':
: undefined reference to `__eqdf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1054): In function `_vfprintf_r':
: undefined reference to `__nedf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x155c): In function `_vfprintf_r':
: undefined reference to `__umoddi3'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1578): In function `_vfprintf_r':
: undefined reference to `__udivdi3'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1834): In function `_vfprintf_r':
: undefined reference to `__ltdf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1d98): In function `cvt':
: undefined reference to `__eqdf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1e10): In function `cvt':
: undefined reference to `__nedf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1e30): In function `cvt':
: undefined reference to `__negdf2'
/gnude/arm-elf/lib/libc.a(dtoa.o)(.text+0x7c): In function `_dtoa_r':
: undefined reference to `__eqdf2'
not sure what i should do next. i think i'll start by removing the explicit libc.a from the linker command line.
it seems I can no longer compile my code in GCC post Ubuntu 11.10 update, despite linking in the libraries with -l. Compiling with:
gcc -lm -lGL -lGLU -lglut T1.c
(The two libraries i'm trying to link and have as includes are glut and math)
All the libraries and header files are where they're supposed to be (they haven't gone anywhere since the update) and i've checked all my relevant package installations. In addition here are my environment variables and they seem to be in order:
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
C_INCLUDE_PATH=/usr/include
I don't think it's a problem with the code as i'm unable to compile files I successfully compiled yesterday. But i'll link it anyway just in case:
#include <math.h>
#include <GL/glut.h>
const int WIDTH=640;
const int HEIGHT=480;
const float NEAR_CLIP=0.1f;
const float FAR_CLIP=100.0f;
const double INC_ROTATE=5;
double rotate=0;
void rotateObject() {
rotate+=INC_ROTATE;
}
void update() {
//rotateObject();
}
void drawAxes() {
double x = 1.5, y = 1.5, z = 1.5;
glLineWidth(4);
glBegin(GL_LINES);
glColor3d(1,0,0);
glVertex3d(0,0,0);
glVertex3d(x,0,0);
glColor3d(0,1,0);
glVertex3d(0,0,0);
glVertex3d(0,y,0);
glColor3d(0,0,1);
glVertex3d(0,0,0);
glVertex3d(0,0,z);
glEnd();
glLineWidth(1);
}
void render() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(1.2,1.0,2.5,0.0,0.0,0.0,0.0,1.0,0.0);
drawAxes();
glColor3d(1,1,1);
glRotated(rotate,0,0,1);
glutWireCube(1);
}
void display() {
update();
render();
}
void reshape(int width, int height) {
float fAspect=0;
float fovy=(M_PI/3);
float top=tan(fovy*0.5)*NEAR_CLIP;
float bottom=top;
float left=fAspect*bottom;
float right=fAspect*top;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left,right,bottom,top,NEAR_CLIP, FAR_CLIP);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv) {
glClearColor(0,0,0,1);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("T1");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(display);
glutMainLoop();
return 1;
}
Error messages:
T1.c:(.text+0x63): undefined reference to `glLineWidth'
T1.c:(.text+0x6d): undefined reference to `glBegin'
T1.c:(.text+0x82): undefined reference to `glColor3d'
T1.c:(.text+0x93): undefined reference to `glVertex3d'
T1.c:(.text+0xa5): undefined reference to `glVertex3d'
T1.c:(.text+0xba): undefined reference to `glColor3d'
T1.c:(.text+0xcb): undefined reference to `glVertex3d'
T1.c:(.text+0xe1): undefined reference to `glVertex3d'
T1.c:(.text+0xf6): undefined reference to `glColor3d'
T1.c:(.text+0x107): undefined reference to `glVertex3d'
T1.c:(.text+0x11d): undefined reference to `glVertex3d'
T1.c:(.text+0x122): undefined reference to `glEnd'
T1.c:(.text+0x12f): undefined reference to `glLineWidth'
/tmp/cc4VqRwQ.o: In function `render':
T1.c:(.text+0x143): undefined reference to `glClear'
T1.c:(.text+0x148): undefined reference to `glLoadIdentity'
T1.c:(.text+0x18a): undefined reference to `gluLookAt'
T1.c:(.text+0x1b1): undefined reference to `glColor3d'
T1.c:(.text+0x1ce): undefined reference to `glRotated'
T1.c:(.text+0x1db): undefined reference to `glutWireCube'
/tmp/cc4VqRwQ.o: In function `reshape':
T1.c:(.text+0x22e): undefined reference to `tan'
T1.c:(.text+0x28a): undefined reference to `glViewport'
T1.c:(.text+0x294): undefined reference to `glMatrixMode'
T1.c:(.text+0x299): undefined reference to `glLoadIdentity'
T1.c:(.text+0x2da): undefined reference to `glFrustum'
T1.c:(.text+0x2e4): undefined reference to `glMatrixMode'
/tmp/cc4VqRwQ.o: In function `main':
T1.c:(.text+0x30b): undefined reference to `glClearColor'
T1.c:(.text+0x31e): undefined reference to `glutInit'
T1.c:(.text+0x328): undefined reference to `glutInitDisplayMode'
T1.c:(.text+0x337): undefined reference to `glutInitWindowPosition'
T1.c:(.text+0x346): undefined reference to `glutInitWindowSize'
T1.c:(.text+0x350): undefined reference to `glutCreateWindow'
T1.c:(.text+0x35d): undefined reference to `glutDisplayFunc'
T1.c:(.text+0x367): undefined reference to `glutReshapeFunc'
T1.c:(.text+0x374): undefined reference to `glutIdleFunc'
T1.c:(.text+0x379): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
I honestly have no clue why gcc can't find the required source files. Any help you could supply would be greatly appreciated, thanks in advance.
EDIT:
I'm using freeglut
Added error messages
I'm guessing ld (the linker) has been changed to work a bit differently.
Put your libraries after the source file
gcc T1.c -lm -lGL -lGLU -lglut
Or apt-get install binutils-gold , apparently the new gold linker will still process dependent shared libraries even if they appear first on the command line.