I have a bit of code that uses iconv() on Linux to validate a string as being UTF-8 encoded. The conversion I create like:
iconv_t c = iconv_open("UTF-8","UTF-8");
I run iconv() like:
int status = iconv(c, &fromArray, (size_t*)&inSize, &toArray, (size_t*)&outSize);
I then take the string to have valid UTF-8 if status is not -1.
This compiles and works fine in a 32 bit environment (where it was initially developed and tested). However I now have a requirement to get this working in a 64 bit environment (to be specific the 64 bit flavor of Fedora 14 I believe). When I compile and run a test on this there status is always -1 and I always get an EILSEQ error in errno, even for the same string which the 32 bit compile says is fine.
Does anyone have any ideas as to why this might be happening?
Recently had experienced same issue. Casting to (size_t*) is more (very) likely the root cause.
The problem even could be easy simulated with next code:
cat >Makefile <<EOF
all: build test clean
clean:
rm -f *.o core* t32 t64
test: build
#echo ; echo "run_32bit version:" ; ./t32
#echo ; echo "run_64bit version:" ; ./t64
build:
g++ -m32 t.cpp -o t32 -Wall -O0 -g
g++ t.cpp -o t64 -Wall -O0 -g
EOF
cat >t.cpp <<EOF
#include <errno.h>
#include <stdio.h>
#include <iconv.h>
char buff_toArray [BUFSIZ];
char buff_fromArray [] = \
"<TESTS_STRINGS>\
<T_VERIFICATION_STRINGS/>\
</TESTS_STRINGS>";
void iconv_test ( const char* desc, size_t* size )
{
printf ("%s = size[%zu]\n",desc, (*size) );
}
int main (int argc, char* argv[])
{
char* toArray = &buff_toArray[0];
char* fromArray = &buff_fromArray[0];
const int inSize_const = 61;
short inSize_short = (short) sizeof(buff_fromArray);
int inSize_int = (int) sizeof(buff_fromArray);
unsigned int inSize_uint = (unsigned int) sizeof(buff_fromArray);
long inSize_long = (long) sizeof(buff_fromArray);
long long inSize_llong = (long long) sizeof(buff_fromArray);
size_t inSize_size_t = sizeof(buff_fromArray);
printf ("fake iconv usage:\n");
iconv_test((const char*) "inSize_const", (size_t*)&inSize_const);
iconv_test((const char*) "inSize_short", (size_t*)&inSize_short);
iconv_test((const char*) "inSize_int", (size_t*)&inSize_int);
iconv_test((const char*) "inSize_uint", (size_t*)&inSize_uint);
iconv_test((const char*) "inSize_long", (size_t*)&inSize_long);
iconv_test((const char*) "inSize_llong", (size_t*)&inSize_llong);
iconv_test((const char*) "inSize_size_t", &inSize_size_t);
printf ("real iconv usage:\n");
int inSize = sizeof(buff_fromArray);
int outSize = sizeof(buff_toArray);
iconv_t c = iconv_open("UTF-8","UTF-8");
int status = iconv(c, &fromArray, (size_t*)&inSize, &toArray, (size_t*)&outSize);
printf ("status=[%d], errno=[%d] \n", status, errno );
printf ("result string:\n");
for(size_t i = 0; i <= sizeof(buff_toArray); i++) { printf ("%c", buff_toArray[i]); }
printf ("\n");
int close_status = iconv_close(c);
printf ("close status=[%d], errno=[%d] \n", close_status, errno );
return 0;
}
EOF
Related
I want to debug an application where some threads seem to go into a deadlock situation in a production environment (I cannot debug, thus I need a meaningful log). I found boost::stacktrace::stacktrace(), but it dumps info for all threads.
Is it possible to limit the output to a specific thread?
If it is Linux specific you can use backtrace and backtrace_symbols to retrieve the backtrace for that specific thread.
I adapted this example from man backtrace to include a thread.
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <thread>
#define BT_BUF_SIZE 100
void printbt(void)
{
int j, nptrs;
void *buffer[BT_BUF_SIZE];
char **strings;
nptrs = backtrace(buffer, BT_BUF_SIZE);
printf("backtrace() returned %d addresses\n", nptrs);
/* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
would produce similar output to the following: */
strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}
for (j = 0; j < nptrs; j++)
printf("%s\n", strings[j]);
free(strings);
}
static void myfunc2(void)
{
printbt();
}
void myfunc(int ncalls)
{
if (ncalls > 1)
myfunc(ncalls - 1);
else
myfunc2();
}
int main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "%s num-calls\n", argv[0]);
return 0;
}
std::thread th( myfunc, atoi(argv[1]) );
th.join();
}
You have to compile with -rdynamic to work
$ g++ -g3 -rdynamic test2.cpp -o /tmp/test2 -lpthread
Running it provides
$ /tmp/test2 3
backtrace() returned 13 addresses
/tmp/test2(_Z7printbtv+0x32) [0x55e2dbe5d37b]
/tmp/test2(+0x4451) [0x55e2dbe5d451]
/tmp/test2(_Z6myfunci+0x29) [0x55e2dbe5d47d]
/tmp/test2(_Z6myfunci+0x22) [0x55e2dbe5d476]
/tmp/test2(_Z6myfunci+0x22) [0x55e2dbe5d476]
/tmp/test2(_ZSt13__invoke_implIvPFviEJiEET_St14__invoke_otherOT0_DpOT1_+0x36) [0x55e2dbe5e0af]
/tmp/test2(_ZSt8__invokeIPFviEJiEENSt15__invoke_resultIT_JDpT0_EE4typeEOS3_DpOS4_+0x4a) [0x55e2dbe5dffd]
/tmp/test2(_ZNSt6thread8_InvokerISt5tupleIJPFviEiEEE9_M_invokeIJLm0ELm1EEEEvSt12_Index_tupleIJXspT_EEE+0x47) [0x55e2dbe5df4d]
/tmp/test2(_ZNSt6thread8_InvokerISt5tupleIJPFviEiEEEclEv+0x2b) [0x55e2dbe5deef]
/tmp/test2(_ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJPFviEiEEEEE6_M_runEv+0x20) [0x55e2dbe5dec0]
/lib/x86_64-linux-gnu/libstdc++.so.6(+0xd6de4) [0x7f306312ede4]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8609) [0x7f3063242609]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7f3062f6a133]
You can use __cxa_demangle to automatically demangle the symbols or you can simply use c++filt from gcc for that.
$ echo _ZSt13__invoke_implIvPFviEJiEET_St14__invoke_otherOT0_DpOT1_+0x36 | c++filt
void std::__invoke_impl<void, void (*)(int), int>(std::__invoke_other, void (*&&)(int), int&&)+0x36
$ echo _Z6myfunci+0x29 | c++filt
myfunc(int)+0x29
You can then go into gdb and look what line the offset 0x29 corresponds to inside the function myfunc(int)
I am asking this question again as the mods decided to close my question here as a duplicate, within minutes of it being asked (and also down-voted!!). Now I have gone through all 33 answers of what was thought to be an answer to my solution, but it didn't help. So I am asking again.
I am trying to build a FreeSWITCH module to add text-to-speech functionality using AWS Polly & the AWS C++ SDK.
Dev environment is Debian 8, g++ 4.9.2. AWS C++ SDK is built using instructions here except that I turned off shared libs (produces .a lib files).
The AWS C++ SDK was built as recommended here (basically C++ code with C++ linkage). mod_polly.cpp is built with C++ linkage as well to produce mod_polly.so. It does refer to some C headers & functions. This was built as -
g++ -shared -o mod_polly.so -L/usr/local/lib/ -laws-cpp-sdk-polly -laws-cpp-sdk-core -fPIC -g -ggdb -std=c++11 -Wall -Werror -I/usr/src/freeswitch/src/include/ -I/usr/src/freeswitch/libs/libteletone/src/ mod_polly.cpp
Source below -
extern "C" {
#include <switch.h>
}
#include <fstream>
#define BIG_ENDIAN_SYSTEM (*(uint16_t *)"\0\xff" < 0x100)
#define REVERSE_BYTES(...) do for(size_t REVERSE_BYTES=0; REVERSE_BYTES<sizeof(__VA_ARGS__)>>1; ++REVERSE_BYTES)\
((unsigned char*)&(__VA_ARGS__))[REVERSE_BYTES] ^= ((unsigned char*)&(__VA_ARGS__))[sizeof(__VA_ARGS__)-1-REVERSE_BYTES],\
((unsigned char*)&(__VA_ARGS__))[sizeof(__VA_ARGS__)-1-REVERSE_BYTES] ^= ((unsigned char*)&(__VA_ARGS__))[REVERSE_BYTES],\
((unsigned char*)&(__VA_ARGS__))[REVERSE_BYTES] ^= ((unsigned char*)&(__VA_ARGS__))[sizeof(__VA_ARGS__)-1-REVERSE_BYTES];\
while(0)
#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentials.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/utils/Outcome.h>
#include <aws/polly/PollyClient.h>
#include <aws/polly/model/SynthesizeSpeechRequest.h>
#include <aws/polly/model/SynthesizeSpeechResult.h>
#include <aws/polly/model/TextType.h>
#include <aws/polly/model/LanguageCode.h>
#include <aws/polly/model/OutputFormat.h>
#include <aws/polly/model/VoiceId.h>
typedef unsigned long DWORD; // 32-bit unsigned integer
typedef unsigned short WORD; // 16-bit unsigned integer
struct riff // Data Bytes Total
{
char chunkID[4]; // "RIFF" 4 4
DWORD riffSize; // file size - 8 4 8
char typeID[4]; // "WAVE" 4 12
char formatChunkID[4]; // "fmt " 4 16
DWORD formatChunkSize; // 16 bytes 4 20
WORD formatTag; // 2 22
WORD noOfChannels; // 2 24
DWORD samplesPerSec; // 4 28
DWORD bytesPerSec; // 4 32
WORD blockAlign; // 2 34
WORD bitsPerSample; // 2 36
char dataChunkID[4]; // "data" 4 40
DWORD dataChunkSize; // not fixed 4 44
};
static struct {
switch_mutex_t *mutex;
switch_thread_rwlock_t *running_rwlock;
switch_memory_pool_t *pool;
int running;
} process;
static struct {
Aws::Auth::AWSCredentials *credentials;
Aws::Client::ClientConfiguration *config;
Aws::SDKOptions *options;
} globals;
switch_loadable_module_interface_t *MODULE_INTERFACE;
static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
/* Prototypes */
SWITCH_MODULE_LOAD_FUNCTION(mod_polly_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_polly_shutdown);
SWITCH_MODULE_DEFINITION(mod_polly, mod_polly_load, mod_polly_shutdown, NULL);
// ------------------------------------------------------------------------------------------------------------------
/* Implementation */
std::ostream& operator<<(std::ostream& out, const riff& h)
{
if BIG_ENDIAN_SYSTEM {
struct riff hdr = std::move(h);
REVERSE_BYTES(hdr.riffSize);
REVERSE_BYTES(hdr.formatChunkSize);
REVERSE_BYTES(hdr.formatTag);
REVERSE_BYTES(hdr.noOfChannels);
REVERSE_BYTES(hdr.samplesPerSec);
REVERSE_BYTES(hdr.bytesPerSec);
REVERSE_BYTES(hdr.blockAlign);
REVERSE_BYTES(hdr.bitsPerSample);
REVERSE_BYTES(hdr.dataChunkSize);
return out
.write(hdr.chunkID, 4)
.write((const char *)&hdr.riffSize, 4)
.write(hdr.typeID, 4)
.write(hdr.formatChunkID, 4)
.write((const char *)&hdr.formatChunkSize, 4)
.write((const char *)&hdr.formatTag, 2)
.write((const char *)&hdr.noOfChannels, 2)
.write((const char *)&hdr.samplesPerSec, 4)
.write((const char *)&hdr.bytesPerSec, 4)
.write((const char *)&hdr.blockAlign, 2)
.write((const char *)&hdr.bitsPerSample, 2)
.write(hdr.dataChunkID, 4)
.write((const char *)&hdr.dataChunkSize, 4);
} else {
return out
.write(h.chunkID, 4)
.write((const char *)&h.riffSize, 4)
.write(h.typeID, 4)
.write(h.formatChunkID, 4)
.write((const char *)&h.formatChunkSize, 4)
.write((const char *)&h.formatTag, 2)
.write((const char *)&h.noOfChannels, 2)
.write((const char *)&h.samplesPerSec, 4)
.write((const char *)&h.bytesPerSec, 4)
.write((const char *)&h.blockAlign, 2)
.write((const char *)&h.bitsPerSample, 2)
.write(h.dataChunkID, 4)
.write((const char *)&h.dataChunkSize, 4);
}
}
riff init_pcm_header(std::ostream& in)
{
// get length of file
in.seekp(0, in.end);
DWORD sz = in.tellp();
in.seekp(0, in.beg);
struct riff result = {
{'R','I','F','F'}, // chunkID
sz + 0x24, // riffSize (size of stream + 0x24) or (file size - 8)
{'W','A','V','E'}, // typeID
{'f','m','t',' '}, // formatChunkID
16, // formatChunkSize
1, // formatTag (PCM)
1, // noOfChannels (mono)
8000, // samplesPerSec (8KHz)
16000, // bytesPerSec ((Sample Rate * BitsPerSample * Channels) / 8)
2, // blockAlign ((bits per sample * channels) / 8)
16, // bitsPerSample (multiples of 8)
{'d','a','t','a'}, // dataChunkID
sz // dataChunkSize (sample size)
};
return result;
}
struct voice_sync {
char* session_uuid;
Aws::IOStream *audio_stream;
switch_size_t blockAlign;
};
typedef struct voice_sync voice_sync_t;
static switch_status_t polly_file_open(switch_file_handle_t *handle, const char *path)
{
voice_sync_t *sync_info = (voice_sync_t*)malloc(sizeof(voice_sync_t));
sync_info->audio_stream = new Aws::StringStream(std::ios::in | std::ios::out | std::ios::binary);
handle->private_info = sync_info;
handle->samplerate = 8000;
handle->channels = 1;
handle->pos = 0;
handle->format = 0;
handle->sections = 0;
handle->seekable = 0;
handle->speed = 0.5;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "submitting text [%s] to polly", path);
Aws::Polly::PollyClient polly_client(*globals.credentials, *globals.config);
Aws::Polly::Model::SynthesizeSpeechRequest request;
request.SetLanguageCode(Aws::Polly::Model::LanguageCode::en_US);
request.SetOutputFormat(Aws::Polly::Model::OutputFormat::pcm);
request.SetSampleRate("8000");
request.SetTextType(Aws::Polly::Model::TextType::text); // or ssml
request.SetVoiceId(Aws::Polly::Model::VoiceId::Matthew);
request.SetText(path);
if (handle->params) {
// get the session UUID for this channel
// note: this doesnt fire for a standard call session in the audio context; is there a way to make sure it is there?
const char *uuid = switch_event_get_header(handle->params, "session");
if (!zstr(uuid)) {
sync_info->session_uuid = switch_core_strdup(handle->memory_pool, uuid);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(sync_info->session_uuid), SWITCH_LOG_DEBUG, "Polly linked to session %s\n", sync_info->session_uuid);
}
}
sync_info->audio_stream->clear();
// sync_info->audio_stream.open(filename.c_str(), std::ios::out | std::ios::binary);
auto outcome = polly_client.SynthesizeSpeech(request);
// Output operation status
if (outcome.IsSuccess()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "received audio response for %s", request.GetServiceRequestName());
Aws::Polly::Model::SynthesizeSpeechResult& result = ((Aws::Polly::Model::SynthesizeSpeechResult&)(outcome));
Aws::IOStream* audio_stream = &result.GetAudioStream();
// this is raw PCM so we need to add a wav header!
riff header = init_pcm_header(*audio_stream);
*sync_info->audio_stream << header;
// tansfer audio data into stream
*sync_info->audio_stream << audio_stream->rdbuf();
sync_info->audio_stream->seekp(0, sync_info->audio_stream->beg);
// update handle information about audio stream
handle->samplerate = header.samplesPerSec;
handle->channels = header.noOfChannels;
handle->format = header.formatTag;
handle->duration = header.dataChunkSize / header.bytesPerSec +1;
handle->samples_in = header.dataChunkSize / header.blockAlign +1;
sync_info->blockAlign = header.blockAlign;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "polly audio stream ready; duration: %ld secs", handle->duration);
return SWITCH_STATUS_SUCCESS;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "something went wrong retrieving audio from polly");
return SWITCH_STATUS_FALSE;
}
static switch_status_t polly_file_close(switch_file_handle_t *handle)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "closiing polly audio stream");
voice_sync_t *sync_info = (voice_sync_t*)handle->private_info;
//sync_info->audio_stream->close(); -- doesnt exist on stringstream
delete sync_info->audio_stream;
if (sync_info->session_uuid) {
switch_safe_free(sync_info->session_uuid);
}
switch_safe_free(sync_info);
handle->private_info = NULL;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t polly_file_read(switch_file_handle_t *handle, void *data, size_t *len)
{
voice_sync_t *sync_info = (voice_sync_t*)handle->private_info;
switch_size_t bytes;
sync_info->audio_stream->read((char *)data, *len * sync_info->blockAlign);
if ((bytes = sync_info->audio_stream->gcount()) <= 0) {
return SWITCH_STATUS_FALSE;
}
*len = bytes / sync_info->blockAlign;
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_polly_load)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Initializing polly audio interface");
supported_formats[0] = (char*)"polly";
/*
switch_application_interface_t *app_interface;
switch_api_interface_t *api_interface;
*/
switch_file_interface_t *file_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
file_interface = (switch_file_interface_t*)switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
file_interface->interface_name = modname;
file_interface->extens = supported_formats;
file_interface->file_open = polly_file_open;
file_interface->file_close = polly_file_close;
file_interface->file_read = polly_file_read;
MODULE_INTERFACE = *module_interface;
memset(&process, 0, sizeof(process));
memset(&globals, 0, sizeof(globals));
process.pool = pool;
switch_thread_rwlock_create(&process.running_rwlock, pool);
switch_mutex_init(&process.mutex, SWITCH_MUTEX_NESTED, pool);
globals.options = new Aws::SDKOptions();
globals.options->loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
globals.credentials = new Aws::Auth::AWSCredentials();
globals.credentials->SetAWSAccessKeyId("your aws key");
globals.credentials->SetAWSSecretKey("your aws secret");
globals.config = new Aws::Client::ClientConfiguration();
globals.config->region = "eu-west-1"; // Ireland
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Initializing aws api");
Aws::InitAPI(*globals.options);
switch_thread_rwlock_wrlock(process.running_rwlock);
process.running = 1;
switch_thread_rwlock_unlock(process.running_rwlock);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ready to rock!");
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_polly_shutdown)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutting down polly polly audio interface");
switch_thread_rwlock_wrlock(process.running_rwlock);
process.running = 0;
switch_thread_rwlock_unlock(process.running_rwlock);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Closing aws api");
Aws::ShutdownAPI(*globals.options);
delete globals.credentials;
delete globals.config;
delete globals.options;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Module shutdown finished");
return SWITCH_STATUS_UNLOAD;
}
Now when i try to load this on Freeswitch , it throws an error
2019-07-31 22:00:51.918181 [CRIT] switch_loadable_module.c:1522 Error Loading module /usr/local/freeswitch/mod/mod_polly.so
/usr/local/freeswitch/mod/mod_polly.so: undefined symbol: _ZNK3Aws35AmazonSerializableWebServiceRequest7GetBodyEv
Freeswitch is C code with C++ guards in header files (extern "C" declaration).
Looking at symbols in mod_polly.so
readelf -Ws mod_polly.so | grep _ZNK3Aws35AmazonSerializableWebServiceRequest7GetBodyEv
66: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _ZNK3Aws35AmazonSerializableWebServiceRequest7GetBodyEv
590: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _ZNK3Aws35AmazonSerializableWebServiceRequest7GetBodyEv
Now my basic understanding of the post here tells me that the symbol is present in the so file but Freeswitch cannot find it or load it.
Now this error has very likely to do with mixing C/C++ code but looking at this and this hasn't helped me figure out how to fix it.
I do not want to build Freeswitch to load my module and I am thinking I shouldn't have to, as that renders this project un-scalable.
What am I missing here?
PS:
readelf -Ws libaws-cpp-sdk-core.a | grep AmazonSerializableWebServiceRequest7GetBodyEv
165: 0000000000000000 716 FUNC GLOBAL DEFAULT 42 _ZNK3Aws35AmazonSerializableWebServiceRequest7GetBodyEv
Symbol is defined in libaws-cpp-sdk-core.a which is part of the compilation command for mod_polly.cpp
#Sam V - turns out it was ordering issue while building. Change in ordering of build command to
g++ -shared -o mod_polly.so -fPIC -g -ggdb -std=c++11 -Wall -Werror -I/usr/src/freeswitch/src/include/ -I/usr/src/freeswitch/libs/libteletone/src/ mod_polly.cpp -L/usr/local/lib/ -laws-cpp-sdk-polly -laws-cpp-sdk-core
fixed the problem. Your 1st comment was the key. Thanks.
I'm getting an eror when I include cstdlib in C++.
Unable to open 'malloc.c': File not found (file:///build/glibc-bfm8X4/glibc-2.23/malloc/malloc.c).
The error comes from the top part of the VS code window.
(the error occurs during debugging.)
Here's some of the code:
#include <cstdlib>
#include <portaudio.h>
//...
static int paCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
/* Cast data passed through stream to our structure. */
paTestData *data = (paTestData*)userData;
float *out = (float*)outputBuffer;
unsigned int i;
(void) inputBuffer; /* Prevent unused variable warning. */
for( i=0; i<framesPerBuffer; i++ )
{
*out++ = data->left_phase; /* left */
*out++ = data->right_phase; /* right */
float currentSample = 0;
char *sampleData = new char[4];
for(int j = 0; j < 4; j++)
{
sampleData[j] = currentBuffer[¤tIndex + j];
}
currentSample = (float)atof(sampleData); //cstdlib is included to use atof
//gets audio sample data and forwards to PortAudio
data->left_phase = currentSample;
data->right_phase = currentSample;
currentIndex += 4;
}
return 0;
}
I'm using Linux Mint 81.1 if that helps.
I've fixed this in the follow way ..
my error is
"Unable to open 'libc-start.c': File not found (file:///build/glibc-OTsEL5/glibc-2.27/csu/libc-start.c"
so I make a dir in the root directory
$cd /
$sudo mkdir build
$cd build
$sudo mkdir glibc-OTsEL5
$cd glibc-OTsEL5
and then download the glibc from internet
$sudo wget http://ftp.gnu.org/gnu/glibc/glibc-2.27.tar.gz
then unpack it
$sudo tar -xzvf glibc-2.27.tar.gz
every thing seems to be ok
This solution is taken from https://github.com/microsoft/vscode-cpptools/issues/811#issuecomment-406544778
I encounter the same problem. The problem is that I did not compile the cpp file with debug flag -g.........When I re-compile the cpp file containing malloc and reinterpret_cast, the problem disappeared.
But I am wrong. The true solution is not to step the line that malloc is in, other wise, the source file of malloc.c is needed.
cf, https://github.com/microsoft/vscode-cpptools/issues/811#issuecomment-559085447
I have a strange error at compilation of the following source :
#include <stdio.h>
#include <stdlib.h>
#include <mach/mach_time.h>
#include <mm_malloc.h>
#ifdef SSE
#include <x86intrin.h>
#define ALIGN 16
void addition_tab(int size, double *a, double *b, double *c)
{
int i;
// Main loop
for (i=size-1; i>=0; i-=2)
{
// Intrinsic SSE syntax
const __m128d x = _mm_loadu_pd(a); // Load two x elements
const __m128d y = _mm_loadu_pd(b); // Load two y elements
const __m128d sum = _mm_add_pd(x, y); // Compute two sum elements
_mm_storeu_pd(c, sum); // Store two sum elements
// Increment pointers by 2 since SSE vectorizes on 128 bits = 16 bytes = 2*sizeof(double)
a += 2;
b += 2;
c += 2;
}
}
#endif
int main(int argc, char *argv[])
{
// Array index
int i;
// Array size as argument
int size = atoi(argv[1]);
// Time elapsed
uint64_t t1, t2;
float duration;
// Two input arrays
double *tab_x;
double *tab_y;
double *tab_z;
// Get the timebase info
mach_timebase_info_data_t info;
mach_timebase_info(&info);
#ifdef NOVEC
// Allocation
tab_x = (double*) malloc(size*sizeof(double));
tab_y = (double*) malloc(size*sizeof(double));
tab_z = (double*) malloc(size*sizeof(double));
#else
// Allocation
tab_x = (double*) _mm_malloc(size*sizeof(double),ALIGN);
tab_y = (double*) _mm_malloc(size*sizeof(double),ALIGN);
tab_z = (double*) _mm_malloc(size*sizeof(double),ALIGN);
#endif
}
If I compile with :
gcc-mp-4.9 -DNOVEC -O0 main.c -o exe
compilation is done but with :
gcc-mp-4.9 -DSSE -O3 -msse main.c -o exe
I get the following error :
main.c: In function 'main':
main.c:96:52: error: 'ALIGN' undeclared (first use in this function)
tab_x = (double*) _mm_malloc(size*sizeof(double),ALIGN);
However, variable ALIGN is defined if I pass SSE macro with gcc-mp-4.9 -DSSE, isn't it ?
I found out the root cause into your script: you are not isolating the novec so the compilation with NOVEC macro is always done. You could isolate it using:
if [ "$1" == "novec" ]; then
# Compile no vectorized and vectorized executables
$GCC -DNOVEC -O0 main_benchmark.c -o noVectorizedExe
$GCC -DNOVEC -O0 main_benchmark.c -S -o noVectorizedExe.s
elif [ "$1" == "sse" ]; then
# Compile with SSE
$GCC -DSSE -O3 -msse main_benchmark.c -o vectorizedExe
$GCC -DSSE -O3 -msse main_benchmark.c -S -o vectorizedExe.s
echo "Test"
elif [ "$1" == "avx" ]; then
# Compile with AVX256
$GCC -DAVX256 -O3 -mavx main_benchmark.c -o vectorizedExe
$GCC -DAVX256 -O3 -mavx main_benchmark.c -S -o vectorizedExe.s
fi
EDIT
I Found out it, you have a typo!!
$GCC -DNOVEV -O0 main_benchmark.c -S -o noVectorizedExe.s
should be
$GCC -DNOVEC -O0 main_benchmark.c -S -o noVectorizedExe.s
I have received a .h file to be used as part of a c++ program. I tried every method to link it, yet the undefined reference error is occurring. I'm using NetBeans in ubuntu.
The .h file contains the functions I'm trying to use. And yet the compiler is unable to find the function.
Here's a snippet of the fwlib32.h file since it is too big to insert the whole file:
FWLIBAPI short WINAPI cnc_allclibhndl3( const char *, unsigned short, long, unsigned short * );
FWLIBAPI short WINAPI cnc_upstart3( unsigned short, short, long, long ) ;
FWLIBAPI short WINAPI cnc_upstart3_f( unsigned short, short, char *, char * ) ;
FWLIBAPI short WINAPI cnc_statinfo( unsigned short, ODBST * ) ;
FWLIBAPI short WINAPI cnc_upload3( unsigned short, long *, char * ) ;
FWLIBAPI short WINAPI cnc_upend3( unsigned short ) ;
FWLIBAPI short WINAPI cnc_freelibhndl( unsigned short ) ;
Here's my program file:
#include "fwlib32.h"
#include<pthread.h>
#include<stdio.h>
#include<string.h>
#define BUFSIZE 1280
static unsigned short H;
struct conn_data
{
char ip[100];
short prt;
long tmo;
long pnum;
};
void conn(char *ipadd, short port, long tmout )
{
unsigned short h;
short ret;
ODBST buf;
ret = cnc_allclibhndl3( ipadd, port, tmout, &h ) ;
if ( !ret ) {
cnc_statinfo( h, &buf ) ;
H=h;
}
else
printf( "ERROR!(%d)\n", ret ) ;
}
short upld( long prgnum )
{
unsigned short h=H;
char buf[BUFSIZE+1] ;
short ret ;
long len;
ret = cnc_upstart3( h, 0, prgnum, prgnum ) ;
if ( ret ) return ( ret ) ;
do {
len = BUFSIZE ;
ret = cnc_upload3( h, &len, buf ) ;
if ( ret == EW_BUFFER ) {
continue ;
}
if ( ret == EW_OK ) {
buf[len] = '\0' ;
printf( "%s", buf ) ;
}
if ( buf[len-1] == '%' ) {
break ;
}
} while ( ret == EW_OK ) ;
ret = cnc_upend3( h ) ;
return ( ret ) ;
pthread_exit(&ret);
}
void* start_thread(void * dat)
{
struct conn_data *data;
data = (struct conn_data *)dat;
conn(data->ip, data->prt, data->tmo);
upld(data->pnum);
}
int main()
{
struct conn_data data;
char ip[100];
short prt;
long tmo,pnum;
pthread_t thread1;
int *ptr;
printf("\nEnter the IP address\n");
scanf("%s",ip);
strcpy(data.ip,ip);
printf("\nEnter the port number\n");
scanf("%hd",&prt);
data.prt=prt;
printf("\nEnter the timeout period in seconds\n");
scanf("%ld",&tmo);
data.tmo=tmo;
printf("Enter the program number\n");
scanf("%ld",&pnum);
data.pnum=pnum;
pthread_create(&thread1, NULL, start_thread, (void*)&data);
pthread_join(thread1, (void **) &ptr);
cnc_freelibhndl( H ) ;
return 0;
}
and these are the contents of the compiler window in NetBeans:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux-x86/amit1
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
CLEAN SUCCESSFUL (total time: 56ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/amit1
make[2]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/connect.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/connect.o.d -o build/Debug/GNU-Linux-x86/connect.o connect.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/amit1 build/Debug/GNU-Linux-x86/connect.o -lpthread
build/Debug/GNU-Linux-x86/connect.o: In function `conn(char*, short, long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:22: undefined reference to `cnc_allclibhndl3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:24: undefined reference to `cnc_statinfo'
build/Debug/GNU-Linux-x86/connect.o: In function `upld(long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:37: undefined reference to `cnc_upstart3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:41: undefined reference to `cnc_upload3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:53: undefined reference to `cnc_upend3'
build/Debug/GNU-Linux-x86/connect.o: In function `main':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:88: undefined reference to `cnc_freelibhndl'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/amit1] Error 1
make[2]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 220ms)
I looked at other similar questions and tried to add the library file in the project properties option, or to just create a -lfwlib32 option in the g++ statement. None of them caused any change. The program would still not build. Can anyone please help me?
turns out the libfwlib32.so file is for 32 bit systems, while mine is a 64 bit system. i'll try to run it in the 32 bit system compatibilty