Compiler doesn't find reference to zip_get_num_entries on Windows - c++

I want to use libzip in my program in C++ to extract files from a zip archive. So firstly, I get the number of files in it, get their names and read them. To get the number of files, I use 'zip_get_num_entries'. Its prototype is:
zip_uint64_t zip_get_num_entries(struct zip *, int)
And the way I use this function:
int nbrEntries(0);
zip *archive = zip_open("myZip.zip", 0, 0);
nbrEntries = zip_get_num_entries(archive, 0);
When I wrote this code, Code::Blocks suggested me zip_get_num_entries, so there's no problem of header. But when I compiled, the compiler (MinGW) told me that:
undefined reference to `_imp__zip_get_num_entries'
So I tried its deprecated equivalent, zip_get_num_files and it worked. I included to the project libzip.dll.a that I made with CMake. I had two files: libzip.dll and libzip.dll.a.
I'm sure it's a library problem (notice that I didn't have this problem on MacOS) but I don't know how to solve this. Thank you!
EDIT: I searched their website and read that the implementation of zip_get_num_files was new when they released the library available on the website. So I searched in their Mercurial repo and found versions that were released 2 days ago (a little bit newer than the release on the website, which has almost 1 year). I built it with CMake and it worked!

"Undefined reference" means that there is no definition/implementation (as opposed to declaration/prototype) of the function available. You forgot to link the library. Since you use MinGW with g++, it will take something like -lzip on the command line or as parts of LDFLAGS.
There is a chance that you misconfigured something, too - in which case the symbol name may be different depending on a define. But the most likely case is that you forgot to link the dependency.

I finally succeed to use zip_get_num_entries! I searched their website and read that the implementation of zip_get_num_files was new when they released the library available on the website. So I searched in their Mercurial repo and found versions that were released 2 days ago (a little bit newer than the release on the website, which has almost 1 year). I built it with CMake and it worked!

Related

Assistance including a basic SDK into a C++ program Dev C++

I have been making some applications that I would like to link to discord, specifically with Discord's SDK. The SDK comes with 64 and 32 bit x84 lib files, and a C++ folder full of the includes it needs, so I would assume C++ is supported.
However, I am very terrible at linking libraries or anything at that, and always run into issues when linking. I am using Dev C++ as my IDE, and my code is as follows:
#include <iostream>
#include "Discord/discord.h"
using namespace std;
void InitDiscord()
{
auto discid = 772671910668133376; //Not my actuall discord app ID, but real one does not make a difference
discord::Core* core{};
discord::Core::Create(discid, DiscordCreateFlags_Default, &core);
}
int main(){
InitDiscord();
cout << "Discord active";
while(1){
}
return 0;
}
and I am getting the error:
C:\TDM-GCC-64\x86_64-w64-mingw32\bin\ld.exe Discord Testing.o:Discord Testing.cpp:(.text+0x32): undefined reference to `discord::Core::Create(long long, unsigned long long, discord::Core**)'
for only the line discord::Core::Create(discid, DiscordCreateFlags_Default, &core); and not discord::Core* core{};
I am using C++17 and a newer TDM-GCC compiler, the same one that works for all of my other applications. I am including the .lib files and .dll files in the program's directory, and in the linker the only thing I am using is -discord_game_sdk.dll.lib which is a valid directory. I have also tried discord_game_sdk.dll.lib and putting the library in the same directory as the includes: Discord/discord_game_sdk.dll.lib. I have tried using both 32 bit and 64 bit libraries in all project and compiler directories with no change, and im sure this is something probably really simple, but nowhere have I found any example C++ discord programs or how to include their SDK.
If anyone could figure out what the problem is and how I can fix it, that would be very helpful and appreciated.
EDIT:
It appears that user4581301 was right, TDM-GCC and other Mingw compilers do not support .lib files, and will ignore them despite being linked. The SDK did not come with any other formats other than .dylib, .so, and .bundle.
This creates a somewhat new issue, I already have my compiler set up and cannot really switch to Visual Studio, so I need a way to convert .lib to .a somehow. A post here recommends http://code.google.com/p/lib2a/ , which requires a .def file, another file that did not come with the SDK, but apparently a program called gendef.exe that came with my compiler can create .def files from .dll files. That is indeed the case, however when attempting it I get the error:
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin>gendef.exe discord_game_sdk.dll
* [discord_game_sdk.dll] Found PE image
* failed to create discord_game_sdk.def ...
with no other warnings. Now I need to know if I am converting wrong, if there is an easier workaround, or if one of the other file types can be converted or used. Any suggestions at this point are welcome and appreciated!

Make ld ignore directory from /etc/ld.so.conf

TL,DR:
Is there a way for me (no root access) to make the linker (invoked by gcc) unaware of the contents of a directory contained in /etc/ld.so.conf after it has been cached via ldconfig?
In Detail:
I'm trying (and failing) to compile HTCondor on a custom linux distro without root access. For various reasons (see below) I believe that the problems I encounter are related to the fact that there are two versions of libssl and two versions of libcrypto installed on this machine. The newer version (1.0.0) of each of these is located at /usr/lib64 and an older version (0.9.8) is kept at /usr/local/lib64 for compatibility reasons. /etc/ld.so.conf contains both of these paths, so the linker knows about both.
During compilation I get an error
../condor_utils/libcondor_utils_8_7_9.so: undefined reference to `ERR_remove_thread_state'
since, for some reason, libcondor_utils_8_7_9.so is linked against libcrypto.so.0.9.8, while ERR_remove_thread_state was introduced in 1.0.0. It appears exactly once in the source code:
#if OPENSSL_VERSION_NUMBER < 0x10000000L
ERR_remove_state( 0 );
#elif OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
ERR_remove_thread_state( 0 );
#endif
so the preprocessor seems to make its decision based on version 1.0.0.
This question made me aware of this blog post, so I tried surrogating cpp with the following script:
#!/bin/bash
/usr/bin/gcc -Wl,-rpath-link="/usr/lib64",-rpath="/usr/lib64" "$#"
to no avail, unfortunately.
Just for the heck of it, I also tried commenting the prepocessor directives in the source code snippet above to force the selection of ERR_remove_state. This results in the linker warning me that libssl.so.1.0.0 may conflict with libssl.so.0.9.8 and, unsurprisingly, produces another "undefined reference" error.
EDIT:
The problem turned out not to be related to the linker at all. See my answer. However, out of curiosity, I'll leave the question open to see if anyone has a solution for it in its original formulation.
The comments by #user463035818 and #jww pointed me in the right direction to solve my specific problem, which turned out not be related to the linker directly.
Condor uses cmake as build system, so obviously it makes more sense to try to solve this at the cmake level (n00b here). Somewhere in the depths of all the things cmake does it finds both versions of the libraries and mixes them up for some reason. Invoking find_library with a specific version as per this answer in the main CMakeLists.txt solves that problem although it leaves a bad taste of dirty workaround in my mouth.
Making cmake ignore a certain directory when looking for libraries should not be hard, according to the docs. I haven't tried it, though.

BOOST_MESSAGE undefined

I have installed boost_1_54 on windows by checkout from svn and then
bootstrap
.\b2
QuantLib library dependent on boost compiles well all but one project: test-suite which uses BOOST_MESSAGE. this is undefined. I can see that there is no BOOST_MESSAGE in my version of boost.
Therefore is this QuantLib incompatibility or have I missed something?
On my linux boost version the same thing applies to BOOST_MESSAGE - it is undefined
I have seen this but I am not sure how to interpret this.
I'm afraid you gave us more credit than we deserved :)
We haven't compiled QuantLib against Boost svn yet. The latest I've tried is Boost 1.53 (the latest released version) in which BOOST_MESSAGE was still available.
Thanks for the heads-up, though. I'll patch the library so that it's ready for next version. As mentioned in the comments, it should be as simple as adding
#if BOOST_VERSION > 105300
#define BOOST_MESSAGE(msg) BOOST_TEST_MESSAGE(msg)
#endif
to test-suite/utilities.hpp.
on linux I had to add
libboost_unit_test_framework.so
to the Linker->Libraries and
#include <boost/test/unit_test.hpp>
#define BOOST_MESSAGE( M ) BOOST_TEST_MESSAGE( M )
is already present in test/test_tools.hpp.
on windows I have different #defines and this is not present, so I added it to the
unit_test_log.hpp
where BOOST_TEST_MESSAGE is defined (in boost files to avoid same issue again in the case of other applications using BOOST_MESSAGE).
BOOST_MESSAGE issue resolved but still can't disambiguate
const void* = boost::test_tools::check_is_close
and
const void* = boost::test_tools::check_is_small
because these are templates. so the solution is to remove it (test-suite compiles well) or use appropriate pointers to function templates
on Windows, after romoval or function
_use_check
in utilities.hpp
changed to not have pointers to TEMPLATE functions as default, so changed to:
void _use_check(
const void*,
const void*) const {}
there were still errors while building test-suite project. unresolved externals: fdmhestonfwdop, fdmblackscholesfwdop, fdmsquarerootfwdop. obviously this classes (headers+source) I had to add to Quantlib project, build library QuantLib-vc110-mt-gd.lib again and rebuild test-suite project then.
after pleasure with VS linker error "lnk1210 exceeded internal ilk size limit link with incremental no" (it really likes RAM, but on windows I have this resource quite limited), it is OK. compiled. : p

OpenCV 2.4 : undefined reference to cvRand

I can't find the file I have to include to my code to get cvRand (and all other related functions, such as cvRandInit ... ) to be recognized by the compiler. It's weird, because in the past this code used to work as is. Must be an issue with OpenCV2.4.
Also, when I right-clic on cvRand (I work with Qt Creator) and ask to follow the symbol under the cursor, the IDE open a file called compat.hpp. I have several files named compat.hpp, so I don't know which one I have to include. My OS is Ubuntu 11.04.
So far, I included core.hpp, highgui.hpp, and cv.h.
I googled on this, but couldn't find any related issue... so I guess this is not an issue, and I just miss something stupid.
The includes were obviously right, I figured that it has to be a lib problem, by guessing I found that I had to add libopencv_legacy.so. Everything works fine now, thx stackoverflow.

please provide the location of the "\msdev\include " directory. to download

I installed EDG compiler in Windows i.e in "win32". After installation I am trying to run this simple code:
using namespace std;
int main()
{
cout<<"OM";
return 0;
}
I am getting errors like unidentified cout, etc
Actually I didn't give path dev libraries : there in read me file it is to give. Later I did gave path to libraries(VS C++ 2010)
Please provide me the MSDEV /include header files to download.
Please provide the location of the "\msdev\include" directory to download.
edit: in readme file they gave "No stream
I/O library is included; this is just very basic support."
if we gave iostream.h also .it shows ..many erros ..regarding that?
EDIT: Otherwise any one
Provide link to download EDG compiler (C++) for windows.Free ware
who already working successively with this....
As far as I see from their page, EDG do not provide a full compiler, but only a front-end; it does not include neither an optimizer/code generator neither a standard library. You simply cannot use just EDG to produce an executable.
You can find several free implementations of the C++ standard library (e.g. libstdc++ from GNU, to which I suppose you should add glibc for the C library subset), but without at least a code-generator backend all you can get from the front-end is the AST of the code gave in input.
Moreover, EDG C++ it's not free, neither it is sold to individuals; EDG license only the source code and only to corporations for a 40K$-250K$ price range. The links you're asking in your question would be illegal.
If you just need a compiler for Windows, there are several great alternatives, both free and not-free, some are listed e.g. in this question.