Compile errors using PST SDK - c++

I am porting a project from Windows to Linux/Ubuntu, which involves using open software called "PST SDK"
(http://pstsdk.codeplex.com) written in c++. This has not been updated since 2010 but it works fine in
Windows and supposedly works/did work in Linux. I set up a demo program with nothing more than including
the header files (the library is all headers, nothing to link). I had a lot of errors but got them
fixed by using g++ instead of gcc, and fiddling with the location of the library files and required
boost files.
However once I tried making some calls, I ran into problems. I got a few things working, but the
following code:
std::vector<pstsdk::folder> folderlist;
folderlist.push_back(folder);
causes this compile error:
error: 'pstsdk::property_bag& pstsdk::property_bag::operator=(const pstsdk::property_bag&)' is private
(There is a lot of other veribiage about what was instantiated from what file). Here is the compile command:
g++ -c -I/usr/local/include -Iboost_1_46_1 -Ipstsdk -I/usr/local/include/mysql ostdemo.cpp
It is specifically the push_back call causing the errors - take that out and they go away. Of course
that is critical to the working of my program. Any idea what this could be? I assume it has
something to do with my compiler version or switches, but I can't figure it out. I am not much of
a c++ programmer so any help would be appreciated.

Your vector::push_back() requires that the type is copy-assignable. Obviously, your pstsdk::folder is not copy-assignable due to the assignment operator being private.
What are the requirements for a type to be placed in a vector? It depends on whether you're using pre-C++11 or C++11, plus what operations you plan to do on these types. See here:
http://en.cppreference.com/w/cpp/container/vector
Pay attention to CopyAssignable, CopyConstructible, MoveAssignable and MoveConstructible
So the case of it working with Windows as opposed to Linux:
Remember that "Windows" and "Linux" are not C++ compilers. You need to expand on this and tell us what version of the g++ compiler you're using on each OS.

Related

In C++11 the signal.h header has no kill function

I just tried compiling code that I wrote a while ago using Gnu g++ in C++11 mode, to see if the code will need reworking anytime soon (I also plan to test it in C++17 mode for the same reason).
I found that the kill() function caused a compiler error and it seems that the kill function no longer exists in the signal.h header.
I just looked at http://www.cplusplus.com/reference/csignal/ as a reference which seems to confirm this is not just a Gnu-specific omission, but seems to be in the standard.
I can't find a rationale for this omission anywhere, nor can I find any proposal for how I should manage processes without it. Can anyone point me in the right direction?
C++ standard function is raise.
kill is a POSIX function that requires POSIX process id pid_t, none of which is required in C++ standard.
OK, I was too quick to post that question, of course fork/kill etc are not part of the C++ standard in the first place but are common additions on unix-like platforms.
My real problem was that I used the wrong compiler switch. For anyone else hitting this problem, to get strict C++11 standard, use:
g++ -std=c++11
But to get the C++11 standard plus non-standard extensions use:
g++ -std=gnu++11
Using the latter, I can build and call fork/kill no problem.

Compile in c++14

So in my CSE course we are given a header file to use right now for our programs that we're writing.
Unfortunately I can't get terminal to compile using that header, it gives quite a few errors (compiling with just 'g++'). Also, when I'm at my university and I'm using PuTTY I get the same errors while using this header. However, I don't get the errors when I compile with 'g++ -std=c++14'.
I've tried compiling with this command on terminal on my mac, but it says it doesn't recognize the c++14 part.
dhcp-10-202-147-243:hw1pr1 Admin$ g++ -std=c++14 hw1pr1.cpp
error: invalid value 'c++14' in '-std=c++14'
Any help on how I could get this to work would be greatly appreciated. Hopefully this all made some sort of sense.
Here's the error I get when I compile with the header file I'm talking about in terminal with just g++.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/hash_map:212:5: warning:
Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
[-W#warnings]
# warning Use of the header <ext/hash_map> is deprecated. Migrate to ...
^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:43:20: error: no matching function for call to object
of type 'hash<char *>'
return hash<char*>()(s.c_str());
^~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/__hash:39:12: note:
candidate function not viable: 1st argument ('const value_type *'
(aka 'const char *')) would lose const qualifier
size_t operator()(char *__c) const _NOEXCEPT
^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:112:8: warning: comparison of unsigned expression < 0
is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
./std_lib_facilities_4.h:118:8: warning: comparison of unsigned expression < 0
is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
3 warnings and 1 error generated.
This error doesn't happen and the program will compile fully when I use PuTTY and 'g++ std=c++14'
There's lots of change between C++ standards, so what is valid in one revision need not be in another.
g++ defaults to -std=gnu++98 for C++, which is the decades old C++98-standard enhanced with GNU extensions (most of which are conformant).
Choose the proper revision: -std=c++1y -pedantic is a very close approximation to C++14.
What changes introduced in C++14 can potentially break a program written in C++11?
Looking at what you say you're having to use and the name format of that .cpp file, I think I'm in the same class. A year later, looks like, but here's my solution for archive's sake:
The std_lib_facilities.h header comes with the Bjarne Stroustrup textbook, "Programming: Principles and Practices Using C++". For those unaware, Bjarne Stroustrup invented C++ (he has a pretty good idea what he's talking about). Incidentally, the book is a fantastic way to learn C++, if one takes the time to actually read it. The std_lib_facilities.h header is just a convenient header file for beginners in C++, containing links to all the major standard libraries used in the textbook, as well as some helper functions that help account for potential mistakes or errors, or are just convenient for learning (such as an error() function that handles simple exception throwing for the student, or adding an "out of bounds" check for vectors). It's ultimately just a way to allow students to hop right into code without having to learn specifics about the header.
Stroustrup keeps updated with C++ and thus includes several libraries that require the c++11 standard. The CSCE department wants its students (at least in this early class) to connect to the department's Unix system and compile from there, in order to avoid confusion with downloading and updating compilers.
I happened to already have had a couple C++ classes beforehand, and thus already had g++ set up on my Ubuntu laptop. I avoided including the std_lib_facilities for as long as possible since I was getting the same error as Topic Creator Joe, where g++ didn't recognize the "c++11" part (manually including the required libraries worked fine until we had to use a class from the textbook that used one of the header's helper functions) . Eventually, I found a help topic online that advised me simply to update my g++ compiler to 4.7 or higher, since 4.6 and lower doesn't have support for C++11 (or, of course, C++14). It was oddly rather involved compared to updates one might be used to on Mac or Windows, and I doubt the exact process would apply, but that is (was?) likely the problem: it's just an older version of g++, and it needs an update to compile C++11 and later. I recommend searching for ways to update g++/gcc for Mac.
Should, y'know, anyone else with this problem stumble upon this and not have their problem solved yet.

Using C++ MySQL Driver on Windows

The actual error is a linker error. Undefined reference to get_driver_instance.
Any ideas what the problem is?
This is what I did to install.
Download and install MinGW to C:\MinGW. http://www.mingw.org/
Download boost and move the boost folder to C:\MinGW\include
Download Connector/C++ 1.1.3 http://dev.mysql.com/downloads/connector/cpp/
Move the mysql_connector/include/*.h (recursively) to C:\MinGW\include\
Move the mysql_connector/lib/mysqlcppconn-static.lib to C:\MinGW\lib\libmysqlcppconn-static.a
Move the mysql_connector/lib/mysqlconncpp.dll to C:\MinGW\lib\mysqlconncpp.dll
Alter cppconn/config.h to remove dupication
Copy the C++ example and name it test.cpp http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html
add "using namespace sql::mysql" to the file (as recommended)
run "g++ test.cpp -L C:\MinGW\lib -l mysqlcppconn-static"
It's likely in a namespace.
throw in this and see what happens:
using namespace sql::mysql;
edit: Also, did you look through the approximately 869 other times people have asked this same question on stack overflow before posting?
https://www.google.com/search?q=mysql+get_driver_instance+site:stackoverflow.com
If that isn't it, it can be a problem with c++ name mangling.
https://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B
Because the name-mangling systems for such features are not standardized across compilers, few linkers can link object code that was produced by different compilers.
and I think the final answer is here:
http://www.mingw.org/wiki/MixingCompilers
another stack overflow answer saying this:
What problems can appear when using G++ compiled DLL (plugin) in VC++ compiled application?
You'll need to build the connector from source using your g++ compiler:
http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-installation-source.html

Undefined reference to operator new

I'm trying to build a simple unit test executable, using cpputest. I've built the cpputest framework into a static library, and am now trying to link that into an executable. However, I'm tied into a fairly complicated Makefile setup, because of the related code.
This is my command line:
/usr/bin/qcc -V4.2.4,gcc_ntoarmle_acpp-ne -lang-c++ -O2 -g -g -o Application/UnitTests/Tests/symbols/UnitTestExe -Wl,--start-group Application/UnitTests/Tests/../.objs/main.o Application/UnitTests/lib/libcpputest.a -Wl,--end-group -lm
I'm getting many errors like the following:
Application/UnitTests/lib/libcpputest.a(CommandLineTestRunner.o): In function `CommandLineTestRunner::parseArguments(TestPlugin*)':
Application/UnitTests/cpputest/src/CppUTest/.objs/../CommandLineTestRunner.cpp:114: undefined reference to `operator new(unsigned int, char const*, int)'
I can't figure out what's causing this. Don't I get operator new for free with C++?
You probably need to link with the C++ support runtime library. This happens automatically when you invoke g++. On Linux, this is achieved by adding the -lstdc++ flag to the linker. You have to figure out how to do the same on your platform.
Maybe you're calling gcc, the C compiler instead of g++, which is the C++ compiler.
There's very little information in your question to work from, but it looks like some code uses some form of placement new, and while that special operator new is declared (the compiler finds it and compiles the code using it), the linker can't find its definition.
(Since this old answer of mine seems to still get attention: See here for an extensive discussion on declaration vs. definition.)
You need to rebuild your code from scratch, including the library. I got this error because I inadvertently copied object files compiled on another machine (with the rest of the source) to my machine. Most likely this disturbs the linking step since there are now two types of object files, native (for modified source files) and non-native (all others). I am guessing here, but the operator 'new' means slightly different things on different architectures and that's why you are getting this error.
p.s. I know this is way too late for a useful answer but I'm still posting this for the record.
For QNX 6.5.0 I have specified flag -lang-c++ for qcc (gcc) to avoid the error.
Like the original post, in my case this error happened while trying to link a software using CppUTest framework.
In my case, the source of the problem seems to be related to the fact I disabled the MEMORY_LEAK_DETECTION compile option of CppUTest. I enabled it again, which solved the problem.
Sometimes adding -lstdc++ is not enough. You should add it to the right place. For example I had list like this, not working:
target_link_libraries(cfr2 pthread m stdc++ "${CMAKE_SOURCE_DIR}/compressor/libcompressor.a" )
But this one works fine:
target_link_libraries(cfr2 pthread m "${CMAKE_SOURCE_DIR}/compressor/libcompressor.a" stdc++)
It'd be great if someone explained it in the comment section.

SIMD Sony Vector Math Library in OS X with C++

I'm currently writing a very simple game engine for an assignment and to make the code a lot nicer I've decided to use a vector math library. One of my lecturers showed me the Sony Vector Math library which is used in the Bullet Physics engine and it's great as far as I can see. I've got it working on Linux nicely but I'm having problems porting it to work on OS X (intel, Snow Leopard). I have included the files correctly in my project but the C++ version of the library doesn't seem to compile. I can get the C version of the library working but it has a fairly nasty API compared to the C++ version and the whole reason of using this library was to neaten the code in the first place.
http://glosx.blogspot.com/2008/07/sony-vector-math-library.html
This blog post that I've stumbled upon seems to suggest something's up with the compiler? It's fairly short so I couldn't take a lot of information from it.
When I try to use the C++ version I get the following errors (expanded view of each error):
/usr/include/vectormath/cpp/../SSE/cpp/vectormath_aos.h:156:0
/usr/include/vectormath/cpp/../SSE/cpp/vectormath_aos.h:156:
error: '__forceinline' does not name a type
second error:
/Developer/apps/gl test/main.cpp:7:0 In file included from /Developer/apps/gl test/main.cpp
/usr/include/vectormath/cpp/vectormath_aos.h:38:0 In file included from
/usr/include/vectormath/cpp/vectormath_aos.h
/usr/include/vectormath/cpp/../SSE/cpp/vectormath_aos.h:330:0 In file included from
/usr/include/vectormath/cpp/../SSE/cpp/vectormath_aos.h
/usr/include/vectormath/cpp/../SSE/cpp/vecidx_aos.h:45:0 Expected constructor, destructor,
or type conversion before '(' token in /usr/include/vectormath/cpp/../SSE/cpp/vecidx_aos.h
Finally two errors at the end of the main.cpp file:
Expected '}' at the end of input
Expected '}' at the end of input
I've Googled my heart out but I can't seem to find any answers or anything to point me in the right direction so any help will be greatly received.
Thanks,
__forceinline is a reserved word that is supported by only a couple compilers. Clearly, your compiler does not support the __forceinline keyword and the code in question is non-portable.
A very poor workaround would be to pass a new define to your compiler that gives the keyword the correct meaning. E.g.: -D__forceinline=inline or -D__forceinline=__attribute__((always_inline)) (Thanks Paul!)
The SSE version was assumed to be only for Microsoft Visual Studio. For other platforms (Mac etc) you can use the scalar version.
Bullet\Extras\vectormathlibrary\include\vectormath\scalar\cpp
It looks like someone's fixed this up and posted a patched version in response to this very issue.
Now GCC compliant.
Which compiler are you using on OS X ? There are 4 to choose from in the standard Xcode 3.2 install and the default is gcc 4.2. You might be better off trying gcc 4.0.