I am using libsndfile and portaudio to play audio from a .wav file and I am getting some weird undefined reference (in time.h...?) errors upon use of sf_open(const char*, int, SF_INFO*) Before showing the errors, here is some basic info: I'm using MinGW 3.21 (cannot upgrade due to IDE constraints) on Windows 10, with CMake as my build system. I have verified that the const char* passed to sf_open is a valid file name and I have checked that no other lines of code are causing this compilation error. Without further ado, have some lovely errors:
libsndfile/lib/libsndfile.a(aiff.o): In function time':
c:/dwimperl/c/bin/../lib/gcc/i686-w64-mingw32
/4.4.7/../../../../i686-w64-mingw32/include/time.h:242:
undefined reference to _time32'
This is printed several times, probably because the function time is used a lot in sf_open although I haven't a clue as to why. This happens as well:
In function `gmtime':
c:/dwimperl/c/bin/../lib/gcc/i686-w64-
mingw32/4.4.7/../../../../i686-w64-mingw32/include/time.h:240:
undefined reference to `_gmtime32'
These errors imply no correlation between sf_open and time.h, but I even tried the following,
#include<sndfile.h>
int main {
sf_open(nullptr, 0, nullptr);
return 0;
}
and gotten the same result. I have libsndfile-1.dll in the same directory as my compiled binaries, and am linking to both libsndfile.a and libsndfile.dll.a. I have tried only linking to libsndfile.a with the same result. However, I tried linking only to libsndfile.dll.a and the program compiled but then crashed, saying:
An error occured while using the portaudio stream
Error number: -9984
Error message: Incompatible host API specific stream info
I'm not sure whether or not that is something for another question, but I thought I'd mention it, seeing that sf_open, the faulty function, seems to do something with stream info. Anyways, this is as far as I've gotten. Help is appreciated!
Look at me being such a genius, answering the question by asking it and then not noticing. Sometimes I wonder how I'm still alive. Anyways, it was simple. Don't link libsndfile.a, just libsndfile.dll.a. That's all. The PortAudio error was something entirely unrelated. Sorry for the idiocy, hope this helps at least one person...?
Related
See below for the following code, and below that, the error that follows.
std::string source = "C:\\Users\\cambarchian\\Documents\\tested";
std::string destination = "C:\\Users\\cambarchian\\Documents\\tester";
std::filesystem::path sourcepath = source;
std::filesystem::path destpath = destination;
std::filesystem::copy_options::update_existing;
std::filesystem::copy(sourcepath, destpath);
terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: cannot copy: File exists [C:\Users\cambarchian\Documents\tested] [C:\Users\cambarchian\Documents\tester]
Tried to use filesystem::copy, along with trying different paths. No luck with anything. Not too much I can write here as the problem is listed above, could be a simple formatting issue. That being said, it worked on my home computer using visual studio 2022, however using VS Code with gcc 11.2 gives me this issue.
Using:
filesystem::copy_file(oldPath, newPath, filesystem::copy_options::overwrite_existing);
The overloads of std::filesystem::copy are documented. You're using the first overload, but want the second:
void copy(from, to) which is equivalent to [overload 2, below] using copy_options::none
void copy(from, to, options)
Writing the statement std::filesystem::copy_options::update_existing; before calling copy doesn't achieve anything at all, whereas passing the option to the correct overload like
std::filesystem::copy(sourcepath, destpath,
std::filesystem::copy_options::update_existing);
should do what you want.
... it worked on my home computer using visual studio 2022 ...
you don't say whether the destination file existed in that case, which is the first thing you should check.
I put the copy_options within the copy function but it didn't work so I started moving it around, I probably should have mentioned that.
Randomly permuting your code isn't a good way of generating clean examples for others to help with.
In the rare event that hacking away at something does fix it, I strongly recommend pausing to figure out why. When you've hacked away at something and it still doesn't work, by all means leave comments to remind yourself what you tried, but the code itself should still be in a good state.
Still doesn't work when I write std::filesystem::copy(sourcepath, destpath, std::filesystem::copy_options::recursive)
Well, that's a different option, isn't it? Were you randomly permuting which copy_options you selected as well?
Trying recursive and update_existing yields the same issue.
The documentation says
The behavior is undefined if there is more than one option in any of the copy_options option group present in options (even in the copy_file group).
so you shouldn't be setting both anyway. There's no benefit to recursively copying a single file, but there may be a benefit to updating or overwriting one. If the destination already exists. Which, according to your error, it does.
Since you do have an error explicitly saying "File exists", you should certainly look at the "options controlling copy_file() when the file already exists" section of the table here.
Visual Studio 2022 fixed the problem
I am using spdlog, opengl, glad, and glfw in my project. No matter what error I am receiving, it is ALWAYS preceded by the 4 same errors. For example, let's say I have the following code:
std::cout << "sup";
then it will run perfectly. Okay now, let's say I have a typo and I do this:
std:cout<< "sup";
I get the following errors:
Here are the first 2 errors.. they redirect to FMT core.h file
and then the last two redirect to FMT format.h
Does anyone know why this could be happening? it is not made or break, whenever I have an error and I fix it these go away but it's just annoying and I would like to understand why.
It looks as though this PR will fix your issue?
https://github.com/fmtlib/fmt/pull/1279
Maybe just update fmt to the latest version?
The Point Cloud library comes with an executable pcl_hdl_viewer_simple that I can run (./pcl_hdl_viewer_simple) without any extra arguments to get live data from a Velodyne LIDAR HDL32.
The source code for this program is supposed to be hdl_viewer_simple.cpp. A simplified version of the code is given on this page which cannot be compiled readily and requires a tiny bit of tweaking to make it compile.
My problem is that the executable that I build myself for both the versions are not able to run. I always get the smart pointer error "Assertion px!=0" error. I am not sure if I am not executing the program in the correct way or what. The executable is supposed to be executed like
./hdl_viewer_simple -calibrationFile hdl32calib.xml -pcapFile file.pcap
in case of playing from previously recorded PCAP files or just ./hdl_viewer_simple if wanting to get live data from the real sensor. However, I always get the assertion failed error.
Has anyone been able to run the executables? I do not want to use the ROS drivers
"Assertion px!=0" is occurring because your pointer is not initialized.
Now that being said, you could initialize it inside your routines, in case the pointer is NULL, especially for data input.
in here, you can try updating the line 83 like this :
CloudConstPtr cloud(new Cloud); //initializing your pointer
and hopefully, it will work.
Cheers,
I'm calling lt_dlopen and getting a generic file not found error (translated errno text). How can I get more information about what is actually failing, as the file is definitely there.
This is a C++ program loading a C++ library. Otherwhere in the same program I use the same command to open other libraries without a problem, thus I fear it might be something specific to this library. I've used ldd and all those dependencies of the library are met.
I stumbled across something that kind of works:
export LD_DEBUG=all
And then proceed to sift throught the extreme mass of output. In this case I found a "lookup error" and one of the symbols could not be resolved. I'm not sure why, but that is perhaps not relevant to this question.
Recompile libtool with "-DLT_DEBUG_LOADERS" in $CFLAGS. Adjust LD_LIBRARY_PATH so that your program will find this debug libltdl.so instead of the system one. That debug version of ltdl will print explicit errors for each loader's attempt to open the target with much less verbosity than LD_DEBUG=all.
From http://www.delorie.com/gnu/docs/libtool/libtool_46.html :
Function: lt_dlhandle lt_dlopen (const char *filename)
[...] If lt_dlopen fails for any reason, it returns NULL.
Function: const char * lt_dlerror (void)
Return a human readable string describing the most recent error that
occurred from any of libltdl's functions. Return NULL if no errors
have occurred since initialization or since it was last called.
I do some image processing work in C++. For this i use CImg.h library which i feel is good for my work.
Here is small piece of code written by me which just reads an image and displays it.
#include "../CImg.h"
#include "iostream"
using namespace std;
using namespace cimg_library;
int main(int argc,char**argv)
{
CImg<unsigned char> img(argv[1]);
img.display();
return 0;
}
When i give lena.pgm as input this code it displays the image. Where as if i give some other image, for example ddnl.pgm which i present in the same directory i get "Segmentation Fault".
When i ran the code using gdb i get the output as follows:
Program received signal SIGSEGV, Segmentation fault.
0x009823a3 in strlen () from /lib/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.9-2.i686 libX11-1.1.4-5.fc10.i386 libXau-1.0.4-1.fc10.i386 libXdmcp-1.0.2-6.fc10.i386 libgcc-4.3.2-7.i386 libstdc++-4.3.2-7.i386 libxcb-1.1.91-5.fc10.i386
Can some one please tell me what the problem is? and how to solve it.
Thank you all
Segfault comes when you are trying to access memrory which you are not allowed to access.
So please check that out in the code.
The code itself looks just fine. I can suggest some ways to go ahead with debugging -
Try removing the display() call. Does the problem still occur? (I'd assume it does).
Try finding out where in the CImg code is the strlen() that causes the segmentation fault (by using a debugger). This may give additional hints.
If it is in the PGM file processing, maybe the provided PGM file is invalid in some way, and the library doesn't do error detection - try opening it in some other viewer, and saving it again (as PGM). If the new one works, comparing the two may reveal something.
Once you have more information, more can be said.
EDIT -
Looking at the extra information you provided, and consulting the code itself, it appears that CImg is failing when trying to check what kind of file you are opening.
The relevant line of code is -
if (!cimg::strcmp(ftype,"pnm")) load_pnm(filename);
This is the first time 'ftype' is used, which brings me to the conclusion that it has an invalid value.
'ftype' is being given a value just a few lines above -
const char *const ftype = cimg::file_type(0,filename);
The file_type() function itself tries to guess what file to open based on its header, probably because opening it based on the extension - failed. There is only one sane way for it to return an invalid value, which would later cause strcmp() to fail - when it fails to identify the file as anything it is familiar with, it returns NULL (0, actually).
So, I reiterate my suggestion that you try to verify that this is indeed a valid file. I can't point you at any tools that are capable of opening/saving PGM files, but I'm guessing a simple Google search would help. Try to open the file and re-save it as PGM.
Another "fun to track down" cause of segmentation faults is compilier mismatches between libraries - this is especially prevalent when using C++ libraries.
Things to check are:
Are you compiling with the same compiler as was used to compile the CImg library?
Are you using the same compiler flags?
Were there any defines that were set when compiling the library that you're not setting now?
Each of these has bitten me in subtle ways before.