Problems with BigInt Library in C++ - c++

So I'm trying out this bigint library: https://mattmccutchen.net/bigint/ on OSX Lion.
I tried making a simple file using the example on their site.
#include <iostream>
#include <bigint/BigIntegerLibrary.hh>
using namespace std;
int main(){
BigInteger a;
int b=5;
a=b;
cout<<a;
return 0;
}
When I compile this in textmate, the output is:
Undefined symbols for architecture x86_64:
  "BigInteger::BigInteger(int)", referenced from:
      _main in ccl9yNN5.o
  "BigInteger::operator=(BigInteger const&)", referenced from:
      _main in ccl9yNN5.o
  "operator<<(std::basic_ostream<char, std::char_traits<char> >&, BigInteger const&)", referenced from:
      _main in ccl9yNN5.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Can anyone tell me what is wrong?

just in case anyone is still looking for answers to this. I found that you have to dig into the Makefile a little bit and figure out how to manually link the program using the Makefile. What I did is in the bigint folder, I ran "make library" once, then later on, I followed the samples at the very end of the Makefile to link the library files together. Here is my Makefile trying to solve an SPOJ problem:

Related

Xcode Linker Flags Stanford Network Analysis Project (SNAP)

I am trying to SNAP with C++ on Xcode. I installed SNAP and provided these two header search paths to Xcode: /usr/local/Cellar/Snap-3.0/snap-core/ and /usr/local/Cellar/Snap-3.0/glib-core/.
But it still produces the error below. I believe I need to fill in "other linker flags" in Xcode, but I can't seem to get it right. Thanks for help.
The C++ Code is below:
#include "Snap.h"
int main() {
return 0;
}
Error Message Below
Undefined symbols for architecture x86_64:
"ExeStop(char const*, char const*, char const*, char const*, int const&)", referenced from:
TRStr::UnRef() in main.o
TRStr::~TRStr() in main.o
TRStr::GetNullRStr() in main.o
"TStr::GetRStr(char const*)", referenced from:
TStr::TStr(char const*) in main.o
ld: symbol(s) not found for architecture x86_64
**clang: error: linker command failed with exit code 1 (use -v to see invocation)**
It works once I add -lSnap.o in "other linker flags" in Xcode

C++ strange behaviour

I am very new to C++ to say the least. However, I cannot find answer to this specific question anywhere.
This is not code specific either, as I tried downloading a lot of code and compiling it via g++ or just make.
It seems that whenever i include a class header in my main() it throws the linker error:
Undefined symbols for architecture x86_64:
"House::getNumBath()", referenced from:
printHouse(House) in houses-91268b.o
"House::getSqft()", referenced from:
printHouse(House) in houses-91268b.o
"House::getColor()", referenced from:
printHouse(House) in houses-91268b.o
"House::House(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, int, double)", referenced from:
_main in houses-91268b.o
"House::House()", referenced from:
_main in houses-91268b.o
"House::~House()", referenced from:
_main in houses-91268b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It happens no matter what code do I download or produce and seems to be related to the constructor function implemented as MyClass::MyClass(/* args */);
Someone suggested that I should include .cpp file in my main instead of .h file, and yes it works. But it's very wrong as I've always been taught that interfaces are meant for it. Otherwise what's their purpose?
With another person suggestion (googled), I am now downloading 10GB worth of Xcode, and hope it helps. Still seems like it's not going to work. What is wrong with C++ here? Am I for some reason missing C++ 11 (again, why on the relatively new OS?) ?
UPDATE:
I grabbed the code from another tutorial that throws me the same thing:
dog.cc
#include "Dog.h"
Dog::Dog() {
}
dog.h
#ifndef DOG_H
#define DOG_H
class Dog {
public:
Dog();
protected:
private:
};
#endif
main.cc
#include "Dog.h"
int main() {
Dog barky;
return 0;
}
Throws both the same after me doing (they are in the same folder, those):
g++ main.cc
or
make ./main
It is probably the simplest example I wanted to try, as I never had problems like this before in C, either using Makefile or by just cc the file.
You need to compile the object (dog.o) file first:
g++ -c dog.cc
Then compile the main with it:
g++ main.cc dog.o

using boost gregorian in iOS

using: xcode 4.6.3. and boost 1.53.0
I'm trying to manipulate dates and times using 'boost::gregorian::days'. It's working perfectly fine when I'm building for OSX 10.8. The problem is when I'm trying to build an iOS app. Everything (including other boost functions) is working fine except the 'gregorian' part. I have used tons of different ways to build boost but I still can't seem to manage to get this part to work.
Is there any way to get this to work?
edit: forgot to mention, I've linked libboost_date_time.a to the project.
sample:
#include "boost/date_time/gregorian/gregorian.hpp"
#include <iostream>
int main()
{
int day = 5;
int month = 8;
int year = 2013;
boost::gregorian::date inputDate(year, month, day);
std::string stringDate = to_iso_extended_string(inputDate)
std::cout << stringDate;
return 0;
}
this gives me the error:
Undefined symbols for architecture i386:
"boost::gregorian::greg_month::as_long_string() const", referenced from:
boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_extended_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in myFile.o
"boost::gregorian::greg_month::as_short_string() const", referenced from:
boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_extended_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in myFile.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

libcurl issue when using D's std.net.curl on Mac

I'm trying to get up to speed using libcurl with D on Mac.
I'm using the latest dmd2 compiler (DMD64 D Compiler v2.062).
The following example compiles and works fine on Windows:
import std.net.curl, std.conv, std.stdio;
void main() {
string content = to!string(get("dlang.org"));
writeln(content);
}
When compiling it on Mac I get the following output:
~/src $ dmd dcurl.d
Undefined symbols for architecture x86_64:
"_curl_easy_cleanup", referenced from:
_D3std3net4curl4Curl8shutdownMFZv in libphobos2.a(curl_1522_37c.o)
"_curl_easy_duphandle", referenced from:
_D3std3net4curl4Curl3dupMFZS3std3net4curl4Curl in libphobos2.a(curl_151e_149.o)
"_curl_easy_init", referenced from:
_D3std3net4curl4Curl10initializeMFZv in libphobos2.a(curl_151d_432.o)
"_curl_easy_perform", referenced from:
_D3std3net4curl4Curl7performMFbZi in libphobos2.a(curl_1528_2fb.o)
"_curl_easy_setopt", referenced from:
_D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionlZv in libphobos2.a(curl_1525_14c.o)
_D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionAxaZv in libphobos2.a(curl_1524_14c.o)
_D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionPvZv in libphobos2.a(curl_1526_14c.o)
_D3std3net4curl4Curl5clearMFE3etc1c4curl10CurlOptionZv in libphobos2.a(curl_1527_207.o)
"_curl_easy_strerror", referenced from:
_D3std3net4curl4Curl11errorStringMFiZAya in libphobos2.a(curl_1520_4a1.o)
"_curl_global_cleanup", referenced from:
_D3std3net4curl4Curl19_sharedStaticDtor29FZv in libphobos2.a(curl.o)
"_curl_global_init", referenced from:
_D3std3net4curl4Curl19_sharedStaticCtor28FZv in libphobos2.a(curl.o)
"_curl_slist_append", referenced from:
_D3std3net4curl3FTP3dupMFZS3std3net4curl3FTP in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl3FTP10addCommandMFAxaZv in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl4HTTP3dupMFZS3std3net4curl4HTTP in libphobos2.a(curl_1517_140.o)
_D3std3net4curl4HTTP16addRequestHeaderMFAxaAxaZv in libphobos2.a(curl_1517_140.o)
"_curl_slist_free_all", referenced from:
_D3std3net4curl3FTP4Impl6__dtorMFZv in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl3FTP13clearCommandsMFZv in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl4HTTP4Impl6__dtorMFZv in libphobos2.a(curl_1517_140.o)
_D3std3net4curl4HTTP19clearRequestHeadersMFZv in libphobos2.a(curl_1517_140.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
--- errorlevel 1
Which seems to imply a linking issue.
I have libcurl at:
/usr/lib/libcurl.3.dylib /usr/lib/libcurl.4.dylib /usr/lib/libcurl.dylib
But I'm not even sure whether dmd is trying to use them.
I've done this before with C/C++ (on the same machine using these libraries) so I think it must be a versioning issue or else I need to pass some flags to the compiler.
Any help would be most appreciated.
You need to link against libcurl. It's not linked against by default. So, instead of
dmd dcurl.d
you need to do
dmd -L-lcurl dcurl.d

Undefined symbols for architecture x86_64: Which architecture should I use?

I'm trying to do some really simple stuff in C++, but I can't find any information on how to tackle this. Even the book I have just says "Just compile and run the program".
test.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Never fear, C++ is here!";
return 0;
}
The compiler says:
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in ccVfJHGs.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccVfJHGs.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccVfJHGs.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccVfJHGs.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I tried compiling with flags like -arch i386 and -m32 but it always says it's the wrong architecture. Which one should I use?
I'm doing this on a Mac but not using XCode, just gcc.
The error isn't that it's the wrong architecture, it's that std::cout (and other symbols) isn't defined.
You should compile and link with g++ not gcc, to automatically link with correct C++ libraries.
The error is caused because you're compiling with gcc, which only default-links libc.
You need to compile with g++ so that libstdc++ is auto-linked in too.
Use g++ instead of gcc to link with exact c++ libraries