Error with zip_open from libzip - c++

I am learning C++, and I decided to make a little program that zip/unzip files to train me.
I downloaded libzip and zlib and linked them to my compiler (MinGW with Code::Blocks on Windows). So I tried to open my zip file with zip_open() and got an error :
undefined reference to _imp__zip_open
Here is the code:
#include <zip.h>
#include <zlib.h>
int main()
{
int error(0);
zip *foo = zip_open("foo.zip", 0, &error);
return 0;
}
I don't know where this is coming from and I would really like some help, because I don't find anything on Google (surely cause the problem is simple).
Thanks in advance!

It looks like you haven't linked to libzip. Make sure you are infact linking to it, and that the path to the lib is in your link path.

Judging by the discussion on this thread from the libzip-discuss list it looks like you are trying to link against a static version of libzip but with the preprocessor symbol ZLIB_DLL defined. You should only have ZLIB_DLL defined if linking against the dll version.

Related

PlaySound in C++ using CLion

I am trying to make a simple C++ program that plays music, but I'm getting this error.
undefined reference to __imp_PlaySoundA'
From what I read I found out that I don't have any source code that implements PlaySound. I know I should add a reference to winmm.lib to my linker, but I only found how to do this in VisualStudio. Is there a way how to do it in CLion? I'm not even sure if CLion has something like that.
#include <iostream>
#include <windows.h>
int main() {
PlaySound("file_name.mp3", nullptr, SND_FILENAME | SND_ASYNC);
return 0;
}
This doesn't help:
What is an undefined reference/unresolved external symbol error and how do I fix it?
I have already solved it, you need to add winMM.Lib to the CMake file. Plus the file can't be .mp3 but .wav (maybe some others, I did't try).
# Link to GLFW, GLEW and OpenGL
target_link_libraries(template PUBLIC
${GLFW_LIBRARIES}
${GLEW_LIBRARIES}
${OPENGL_LIBRARIES}
winMM.Lib)

FATAL ERRORS with compilation after installing Aspose.Cells library for C++

Can someone please help me with my issue with Aspose.Cells library for C++?
I was writing my first C++ programme using Aspose.Cells library. Everything seemed smooth except that the following error was produced after I built the file:
Error before I launch is:
"Error exist in a required project.Continue launch?"
Error after running the code is:
"**fatal error: boost/config/compiler/gcc.hpp: No such file or directory**".**
If I commented out the line #<include Aspose.Cells.h>, the file can run with no errors.
I tried to solve the error by installing Boost library for C++ from zip file "boost_1_73_0", as I think Aspose depends on Boost to run. However, I couldn't link to Boost successfully as there doesn't seem to be a "include" folder and "lib" folder for me to add into project properties.
My questions are:
Will installing Boost solve my problem?
If yes, how can I install Boost library successful?
The following is my code in C++. Thanks a Lot in advance!
#include <iostream>
#include <Aspose.Cells.h>
using namespace std;
int main() {
cout << "!!!I am little red!!!" << endl;
return 0;
}
Regards
Hillary
UPDATE: I have successfully installed and linked Boot library now but I have got three warning message upon building: "Ignoring #pragma warning [-wunknown-pragmas]" , are these warning messages serious?
I also ran into another fatal error: unicode/uloc.h:No such file or directory. How can I correctly link up to unilib-master/Unicode library?
Yes, installing Boost helps.
If Aspose only requires header-only libraries from Boost, then you don't have to do much. The "include" path you're looking for is just the folder where you extracted the zip. The actual library headers are under boost/ in that folder, which are then found by the compiler.
If you need the shared libraries, you will need to build them. Follow the steps here Getting Started On Windows

Undefined reference to std::*something* when linking library staticly

I've compiled some of my code into a static library. Everything from this library begins with Glow or GLOWE prefix. At the moment, I'm testing the library in Linux (Ubuntu 14.04). I made a simple program to check if I did everything correctly.
#include <GlowSystem/Package.h>
int main(void)
{
GLOWE::Package package;
return 0;
}
GLOWE::Package is a class. It uses libzip and zlib (and standard c++ files eg. string). I link both libzip and zlib. When I try to compile, it fails with some linking errors.
Build log (at pastebin)
I thought that these errors are caused by too old libstdc++, but this code compiles:
#include <string>
using namespace std;
int main(void)
{
string a;
a.resize(5000);
return 0;
}
I'm at my wits' end and I have no idea what to do. I will appreciate any help.
It looks like your linker options are incorrect:
../GlowE/GlowEngine/bin/Debug/libGlowEngine.a /usr/lib/x86_64-linux-gnu/libzip.a /usr/lib/x86_64-linux-gnu/libz.a
Try:
-l../GlowE/GlowEngine/bin/Debug/GlowEngine -l/usr/lib/x86_64-linux-gnu/zip -l/usr/lib/x86_64-linux-gnu/z

Compile C++ with static lib

this will probably a dumb question for you guy's but I have no experience in C++ what so ever. I'm using an open source project osrm (which is awesome). Still to request a route, you have make an http request. To reduce the running time, I would like to build a wrapper around the code and call it using the command line. So I googled a bit and found that osrm already creates a static lib (.a file) when compiling the project. I also found a piece of code that points me in the right directions for building a wrapper. So to begin I build a simple hello world program (see below) that includes some files from that static lib. To compile I followed this tutorial.
My directory structure looks like this:
./helloWorld.cpp
./libs/libOSRM.a
And the command to compile is this:
gcc –static helloworld.cpp –L ./libs –l libOSRM.a
The code it selve:
#include "Router.h"
#include "boost/filesystem/path.hpp"
#include "ServerPaths.h"
#include "ProgramOptions.h"
#include <InternalDataFacade.h>
#include <viaroute.hpp>
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
the exact error I got:
fatal error: ServerPaths.h: No such file or directory #include "ServerPaths.h"
Add the -IPathToTheHeaderFiles to the compiler options. So it will find the files to be included. Replace PathToTheHeaderFiles with the path where your file ServPaths.h resides.
Edit: Add as many -I as you need for further header files.
Additionally it would be worth to read a book about C++ or/and the GCC manual1
1 Section 3.11 will help.

Missing cyg*.dll when using libraries compiled with Cygwin, and errors when added

I just compiled zlib and libzip with Cygwin to use them with Code::Blocks in Windows.
My code is that:
#include <iostream>
#include <zip.h>
int main()
{
//Open the ZIP archive
int err = 0;
zip *z = zip_open("main.zip", 0, &err);
zip_close(z);
std::cout << "Hello world!" << std::endl;
return 0;
}
When I build my code, it works well, no errors and warnings.
When I launch my program, it says that I don't have cygzip-2.dll. Okay, I search it and put it in my executable folder. Then, it says that I don't have cygwin1.dll. Okay, I put it too. The same for cygz.dll and cyggcc_s-1.dll.
Oh, it works! But then, my program stops with always the same status: -1073741819.
It doesn't even tell me hello :(
I compiled it with MinGW (it did the same error on Cygwin), and I linked libz.a, libzip.a and libzip.dll.a. Where does the problem could come from?
Thanks!
EDIT: When I try to compile my program IN Cygwin, it says 'undefined reference to '_zip_open'' and 'undefined reference to '_zip_close''. Probably something is missing, but what?
Eventually, I succeeded to use my 2 libraries! I had already tried to use CMake, but failed miserably.
So today, I decided to retry it with the GUI. Firstly, I compiled zlib. I chose the zlib folder, and put the build folder in it. I configured with the option for Code::Blocks and MinGW Makefiles, and native compilers. Then, I opened the .cbp (Code::Blocks Project) in my 'build' folder, and built it.
For libzip, I did the steps except that I specified 2 variables:
ZLIB_INCLUDE_DIR = the root of zlib folder (where there are all the .h and .c) and ZLIB_LIBRARY = [the path to your build folder from zlib]\libzlib.dll
I built it from the .cbp too. And I linked all my files to my project, and it was done!