cannot find boost::throw_exception - no package with Ubuntu [duplicate] - c++

I'm trying to compile/port an older version of OpenOffice. It uses Boost v1.34.1, which is part of the source tree. The error message is as follows:
Undefined symbols:
"boost::throw_exception(std::exception const&)", referenced from:
boost::detail::shared_count::shared_count<ScToken>(ScToken*)in detfunc.o
ld: symbol(s) not found
Boost is new to me, and I haven't been able to find much online to help me understand this. From the error message, I understand that I probably need to link a library. However, boost::throw_exception is defined in a header file with no matching library (that I can find). Just for kicks, I've tried #include <boost/throw_exception.hpp> in detfunc and using symbolic links to put the header file in the same directory with no luck.
Is there a library I should be linking with -l or an include path with -I? How should I get that symbol referenced in?

Boost expects the project either to be built with macro BOOST_NO_EXCEPTIONS undefined, or to define the function boost::throw_exception itself.
From <boost/throw_exception.hpp> in version 1.34.1:
namespace boost
{
#ifdef BOOST_NO_EXCEPTIONS
void throw_exception(std::exception const & e); // user defined
#else
//[Not user defined --Dynguss]
template<class E> inline void throw_exception(E const & e)
{
throw e;
}
#endif
} // namespace boost
Boost's configuration headers will determine whether to define the macro or not. It looks like it boils down to the compiler you're using, but there may be other factors. Take a look in the boost/config/compiler/ folder for the header file that corresponds to your compiler, then search for BOOST_NO_EXCEPTIONS in it. There should be some conditions around the #define to help explain when Boost defines it. You may be able to configure your build to avoid the definition and get past the linker error you're experiencing.
If you're unable to change your compiler config to avoid the definition, then you're probably left defining boost::throw_exception(std::exception const & e) yourself somewhere in the OpenOffice code. I'm unfamiliar with that code, though, so I can't give a good suggestion where it should go.

Related

How do I avoid LNK2005 and LNK1169 errors while compiling TetGen in my project?

I am trying to compile TetGen and use the code below to tetrahedralize a .ply file although I am getting these two linker errors:
LNK2005 main already defined in tetgen.obj
LNK1169 one or more multiply defined symbols found
The files that are includes in my project solution are "tetgen.h", "predicates.cxx", and "tetgen.cxx", and the folder path that these three files are in is included in my Project Properties > C/C++ > General > Additional Include Directories. I did the same for the "monkey.ply" file as well.
This is all the code in my main file:
#include "tetgen.h"
int main()
{
tetgenio in, out;
in.firstnumber = 0;
in.load_ply((char *)"monkey.ply");
tetgenbehavior* b = new tetgenbehavior();
tetrahedralize(b, &in, &out);
}
Here are the "tetgen.h", "predicates.cxx", and "tetgen.cxx" files I'm using : https://minhaskamal.github.io/DownGit/#/home?url=https://github.com/libigl/tetgen
I researched these errors and looked around a great amount but can't see why this is occurring. Any help would be greatly appreciated.
LNK2005 main already defined in tetgen.obj
This message tries to tell you that your tetgen library contains the main function. Your "main file" also contains a main function. This is a conflict. You should remove your main function from your code, and read the documentation of the tetgen library on how to provide a replacement. Typically, libraries which define their own main functions require you to rename your main to have some other name, which the documentation should clearly specify.
#include "tetgen.h"
int main_replacement_called_by_tetgen()
{
...
}
For anyone who may have this issue in the future with TetGen: The problem was that the TETGEN_LIBRARY flag needed to be defined in tetgen.h. I knew this, but every time I defined the flag, it would cause memory errors without fail. So, I kept TETGEN_LIBRARY undefined to avoid the memory error. Turns out, with TETGEN_LIBRARY defined, it will work. The problem was that "monkey.ply" did not exist/was in the wrong folder. Because "monkey.ply" did not exist it threw an unhandled exception. Why TetGen does not have a simple handle to check if a file exists before it tries to load it or not is beyond me. But that fixed things.

Linker error on Mac but not on iOS for any C++ function

Long version: I'm looking to implement my app's model in C++ and use this model everywhere that Cocos2d-x uses C++ so that: (1) I know it has the same version of C++ and (2) I can remove my application's model from Cocos2d-x when the time comes. I'm starting with Mac OS X and iOS, and I'm making sure things compile before I set out with this project. On iOS, everything is working just fine. On Mac, basic C++ gives me a linker error every time!
Short version begin: I have a C++ class that looks like the following:
class GetInteger {
public:
static int GetInt();
};
All's well so far, so let me go ahead and define my super-complicated static function:
int GetInteger::GetInt()
{
return 5;
}
Okay, that's basic C++, I'm now going to go ahead and use my super-complication function:
"include "GetInteger.h"
...
int theInt = GetInteger::GetInt();
...
Things are still super-simple, and in fact, it all works when I compile this code in Xcode for iOS, using the standard settings for a Cocos2d-x project for iOS. But when I try to run this code on a Mac, it get the following error:
Undefined symbols for architecture x86_64:
"GetInteger::GetInt()", referenced from:
AppDelegate::applicationDidFinishLaunching() in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why is this? How do I resolve this?
Here's my project file from ZippyShare.
Your intuition save's my ton's of effort #PLJNS , whoever wants detail can walk through the following steps.
say you have XYZ.h & XYZ.mm which causes the problem.
solution::
select XYZ.h & XYZ.mm and delete them, in the delete dialogue choose "Remove Reference"
Now Add XYZ.h & XYZ.mm by "Add Files to your_project_name".
Now Select All of your target (here i select two of mine MobileDialerNewSt & IPA).
Clean & Build.
Happy coding :)
Make sure your Objective-C files have extension .mm and not .m and try compiling again.
I didn't realize that any file you include must be added to both targets, I just saw that piece of UI this minute. That fixed my issue.
BE SURE TO INCLUDE ALL YOUR FILES TO ALL YOUR TARGETS WITH XCODE

How can I resolve single symbol link error when dynamically linking XCode project to lib4cxx library?

I'm writing in C++ under XCode 4.6 on Mountain Lion. I'm trying to add and use the Apache log4cxx library. I installed the library this morning via Brew. I'm linking against liblog4cxx.dylib. I'm getting a link error that just one symbol can't be found:
Undefined symbols for architecture x86_64:
"log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT
const&, std::__1::basic_string,
std::__1::allocator > const&, log4cxx::spi::LocationInfo const&)
const", referenced from:
I know it's finding the library file because if I remove it, I get lots more undefined symbol errors relating to log4cxx.
relevant code is basically:
#include <log4cxx/logger.h>
static LoggerPtr logger(log4cxx::Logger::getLogger("foo.bar.Baz"));
void foo(int p1, int p2)
{
LOG4CXX_WARN(logger, "blah blah blah");
}
Creating the logger object inside the function, either as static or not, doesn't change the behavior. Also, linking with the static library, with or without defining LOG4CXX_STATIC in my project, does not change the behavior.
Looking at the macro I'm calling, I see that this symbol is the actual method that performs the log operation. If take out the logging call but leave in the code that defines the logger object, the code links fine as you might expect.
What do I need to do to have this last symbol resolve?
TIA!
I traced my issue down to compiling the library in a non C++11 compiler, but then my target project was a C++11 compiler.
I was able to compile log4cxx in a C+11 compiler by viewing the changes to log4cxx in the development git repo, which mainly consisted of inserting static_casts, as in this update:
http://apache-logging.6191.n7.nabble.com/C-11-does-not-allow-char-literals-with-highest-bit-set-unless-cast-td34908.html
I suppose the few incompatible routines came up undefined, which is why we were getting confused with only a few seemingly random undefines. (Or I was anyway)

Possible to hide cv-prefixed functions in OpenCV?

I'm using C++, and compiling & linking to OpenCV2 using "g++". One thing that bothers me is that all of the old cv-prefixed functions are still available and "pollute" my application.
Is it possible to make the OpenCV1 C cv-prefixed functions unavailable in the scope of my application and just keep the OpenCV2 cv:: namespaced ones?
Note: I haven't written C in a while, so please let me know if this is a silly question.
It depends on what do you really need. If you just want to make this code:
CvArr *arr;
cvAvg(arr);
cvAcc(arr, arr);
"not working" - you can just add this:
#define cvAvg nothing_interesting_cvAvg
#define cvAcc nothing_interesting_cvAcc
//you can change nothing_interesting_... to anything, but you can't use the same text more than once
//you include files
//...
//after your include files
#undef cvAvg
#undef cvAcc
before including any OpenCV file. If you now try to compile code you will see:
error C3861: 'cvAvg': identifier not found
If you change you code to use nothing_interesting_cvAvg(arr); instead of cvAvg(arr);, it will compile fine, but linker will fail, because:
: error LNK2019: unresolved external symbol _nothing_interesting_cvAvg referenced in function _main
Note that this will work only for this 2 functions, so you will have to find all functions which you want to "disable" and write similar code manually.
Functions which use "deactivated" functions will work fine, because they are already compiled, linked, etc - you will just call them from some files without changing anything in this files.

Objective-C/C++ - Linker error/Method Signature issue

There is a static class Pipe, defined in C++ header that I'm including.
The static method I'm interested in calling (from Objective-c) is here:
static ERC SendUserGet(const UserId &_idUser,const GUID &_idStyle,const ZoneId &_idZone,const char *_pszMsg);
I have access to an objective-c data structure that appears to store a copy of userID, and zoneID -- it looks like:
#interface DataBlock : NSObject
{
GUID userID;
GUID zoneID;
}
Looked up the GUID def, and it's a struct with a bunch of overloaded operators for equality. UserId and ZoneId from the first function signature are #typedef GUID
Now when I try to call the method, no matter how I cast it (const UserId), (UserId), etc, I get the following linker error:
Ld build/Debug/Seeker.app/Contents/MacOS/Seeker normal i386
cd /Users/josh/Development/project/Mac/Seeker
setenv MACOSX_DEPLOYMENT_TARGET 10.5
/Developer/usr/bin/g++-4.2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -L/Users/josh/Development/TS/Mac/Seeker/build/Debug -L/Users/josh/Development/TS/Mac/Seeker/../../../debug -L/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/gcc/i686-apple-darwin10/4.2.1 -F/Users/josh/Development/TS/Mac/Seeker/build/Debug -filelist /Users/josh/Development/TS/Mac/Seeker/build/Seeker.build/Debug/Seeker.build/Objects-normal/i386/Seeker.LinkFileList -mmacosx-version-min=10.5 -framework Cocoa -framework WebKit -lSAPI -lSPL -o /Users/josh/Development/TS/Mac/Seeker/build/Debug/Seeker.app/Contents/MacOS/Seeker
Undefined symbols:
"SocPipe::SendUserGet(_GUID const&, _GUID const&, _GUID const&, char const*)", referenced from:
-[PeoplePaneController clickGet:] in PeoplePaneController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Is this a type/function signature error, or truly some sort of linker error? I have the headers where all these types and static classes are defined #imported -- I tried #include too, just in case, since I'm already stumbling :P
Forgive me, I come from a web tech background, so this c-style memory management and immutability stuff is super hazy.
Edit: Added full linker error text. Changed "function" to "method". Also I'll note that we're using a custom makefile to compile a few projects external to this one. SocPipe static methods are referenced elsewhere, though, in this xcode project and seems to compile fine.
(Eh, let's turn that comment into an answer.)
The method signature looks fine; that is, what you're calling matches what is declared in the header. If it was not, you would probably be getting a compilation error rather than a linker error.
The linker's problem is that it doesn't have any corresponding object code to connect this call to: the method is declared but never defined.
The latter should occur either in a C++ source file which your project can compile, or else in some precompiled library or framework that you can link to. Either way, that file needs to be included in your project so that it can be made available to the linker.
The object file containing Pipe::SendUserGet is not being built, or it is not being linked into your Xcode target. Whether or not other static methods in Pipe work correctly is not necessarily relevant if those methods are defined in the header file.
You mentioned that you use external makefiles to build parts of your project. In that case, it's not enough to run the makefile at compile time as a dependency — you also have to include the resulting products in your project.
For example, if you have a makefile that builds libLIBRARY.a, then drag libLIBRARY.a into your project and add it to your target.
This only works if the makefile is building a library. It won't work if the makefile builds a program. It also gets more complicated if the library is a dynamic library, as you'll also have to make sure that the dynamic library gets distributed with your application (often by putting it in the app bundle, if you're making an app bundle). It also gets more complicated if you want to build a universal binary. You could theoretically pass the right CFLAGS to make to build a universal library, but it may be easier to run make once for each architecture and combine the results using a script (which is what I do).