How to define a undefinded reference to a function - ubuntu-16.04

I am working on two Beaglebone Black with Xenomai and RTnet. I have two c-files for a roundtrip ethernet frame between the BBB's. When I try to compile the first c-file there occur some errors:
undefined reference to 'rt_task_self'
rt_task_self is a function in my c-file and is declared in my headerfile "task.h". So in my opinion "undefined" means that it is just not defined in any cpp-file "task.cpp" for the headerfile "task.h".
But I am a little bit confused: How do I tell my program that my headerfile "task.h" is defined in my other file "task.cpp" or "task.o" or...
I have many header files in my C-file but only error with my "task.h" file and I do not see any differences in the #include rows between my "task.h" and all the other header files.
Part of Roundtrip C-file:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
/*XENOMAI*/
#include "task.h"
#include <rtdm/rtdm.h>
#include <asm/ioctl.h>
#define SERVER "192.168.127.10"
#define BUFLEN 512
#define PORT 8888
void die(char *s)
{
perror(s);
exit(1);
}
Part of task.h:
#ifndef _XENO_TASK_H
#define _XENO_TASK_H
#include <nucleus/sched.h>
#include <native/types.h>
/* Creation flags. */
#define T_FPU XNFPU
#define T_SUSP XNSUSP
/* <!> High bits must not conflict with XNFPU|XNSHADOW|XNSUSP. */
#define T_CPU(cpu) (1 << (24 + (cpu & 7))) /* Up to 8 cpus [0-7] */
#define T_CPUMASK 0xff000000
Part of another headerfile in the roundtrip c-file:
#ifndef _RTDM_H
#define _RTDM_H
#ifdef __KERNEL__
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/ioctl.h>
#include <linux/sched.h>
#include <linux/socket.h>
typedef u32 socklen_t;
typedef struct task_struct rtdm_user_info_t;
#else /* !__KERNEL__ */
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
My makefile:
# Allow overriding xeno-config on make command line
XENO_CONFIG=xeno-config
prefix := $(shell $(XENO_CONFIG) --prefix)
ifeq ($(prefix),)
$(error Please add <xenomai-install-path>/bin to your PATH variable)
endif
CC := $(shell $(XENO_CONFIG) --skin=posix --cc)
STD_CFLAGS := $(shell $(XENO_CONFIG) --skin=posix --cflags) -g
STD_LDFLAGS := $(shell $(XENO_CONFIG) --skin=posix --ldflags) -g -lrtdm
STD_TARGETS := rtt_rt
all: $(STD_TARGETS)
$(STD_TARGETS): $(STD_TARGETS:%=%.c)
$(CC) -o $# $< $(STD_CFLAGS) $(STD_LDFLAGS)
clean:
$(RM) -f *.o *~ $(STD_TARGETS)

Related

Difficulty adding Paillier algorithm to perceptual hash implementation

Received error:
libNCPH.h:39:15: fatal error: paillier.h: No such file or directory
39 | #include <paillier.h>
In libNCPH.h, it is also in this way:
extern "C" {
#include <gmp.h>
#include <paillier.h>
#include "tcp.h"}

E0020 identifier "sleep" is undefined Visual Studio 2019

The Visual Studio 2019 shows E0020: "Sleep() is undefined" and C3861 'sleep':identifier not found.
I use "windows.h" but it doesn't work.
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <windows.h>
#include <dos.h>
#pragma comment(lib, "pthreadVC2.lib")
using namespace std;
..........
int main() {
pthread_t tid0;
pthread_t tid1;
pthread_create(&tid0, NULL, workerThreadFunc, (void*)&tid0);
pthread_create(&tid1, NULL, workerThreadFunc2, (void*)&tid1);
sleep(1); // E0020 identifier "sleep" is undefined**
THREADS_CREATED = 1;
pthread_exit(NULL);
return 0;
}
the "sleep(1)" should like this "Sleep(1)". The letter "s" should be capitalized.

ffmpeg avcodec_find_encoder_by_name failes to find encoder h264_nvenc

When I run this command "ffmpeg -h encoder=h264_nvenc" in the terminal it gives me the following output
and I am able to use the encoder through the command line interface but it got a problem when I try to run from the following source code.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h>
#include <libavutil/mathematics.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
#include <x264.h>
}
int main( int argc, char** argv )
{
const AVCodec *codec;
AVCodecContext *c= NULL;
av_register_all();
std::cout << "Loading codec" << std::endl;
// codec = avcodec_find_encoder_by_name( "libx264" ); // works
codec = avcodec_find_encoder_by_name( "h264_nvenc" );
// codec = avcodec_find_decoder_by_name( "h264_cuvid" );
if( !codec )
{
throw std::runtime_error( "Unable to find codec!" );
}
std::cout << "Allocating context" << std::endl;
return 0;
}
Here is a clear CMakeLists.txt file for this minimal example. Note that the libraries are not linked correctly if one uses link_directories( /usr/local/lib ), so I used add_library instead.
Furthermore, it seems not to be necessary to include the nvidia/cuda libraries to have access to nvenc codecs.
cmake_minimum_required(VERSION 2.8)
project( opencv-test )
include_directories(/usr/local/include)
add_executable( h264_nvenc
h264_nvenc.cpp
)
# link_directories( /usr/local/lib ) # does not work
add_library( avformat SHARED IMPORTED )
set_target_properties( avformat PROPERTIES IMPORTED_LOCATION /usr/local/lib/libavformat.so )
add_library( avutil SHARED IMPORTED )
set_target_properties( avutil PROPERTIES IMPORTED_LOCATION /usr/local/lib/libavutil.so )
add_library( avcodec SHARED IMPORTED )
set_target_properties( avcodec PROPERTIES IMPORTED_LOCATION /usr/local/lib/libavcodec.so )
add_library( swscale SHARED IMPORTED )
set_target_properties( swscale PROPERTIES IMPORTED_LOCATION /usr/local/lib/libswscale.so )
add_library( swresample SHARED IMPORTED )
set_target_properties( swresample PROPERTIES IMPORTED_LOCATION /usr/local/lib/libswresample.so )
target_link_libraries( h264_nvenc avformat swscale swresample avutil avcodec)
Your code works on my system (finds encoder). Make sure your ffmpeg source is up to date and configured and compiled with --enable-nvenc.
Update:
Can you please save above snipped as h264_nvenc.cpp and compile with this command:
g++ h264_nvenc.cpp -o h264_nvenc `PKG_CONFIG_PATH=/path/ffmpeg/lib/pkgconfig/ pkg-config --cflags libavformat libswscale libswresample libavutil libavcodec` `PKG_CONFIG_PATH=/path/ffmpeg/lib/pkgconfig/ pkg-config --libs libavformat libswscale libswresample libavutil libavcodec` -std=gnu++11
And than test the compiled file as ./h264_nvenc
You should then see:
Loading codec
Allocating context

aes_encrypt() function hooking

I want to know the pid of the process which is performing the AES encryption. I have written the following function hooking code:
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <openssl/aes.h>
void AES_encrypt(const unsigned char *in_var, unsigned char *out_var,
const AES_KEY *key_var)
{
void (*new_aes_encrypt)(const unsigned char *in_var, unsigned char *out_var,
const AES_KEY *key_var);
new_aes_encrypt = dlsym(RTLD_NEXT, "AES_encrypt");
FILE *logfile = fopen("logfile", "a+");
fprintf(logfile, "Process %d:nn%snnn", getpid(), (char *)in_var);
fclose(logfile);
new_aes_encrypt(in_var, out_var, key_var);
}
Then at terminal I did the followings:
#gcc aes_hook.c -o aes_hook.so -fPIC -shared -lssl -D_GNU_SOURCE
#export LD_PRELOAD="/<directory location>/aes_hook.so"
However, when I started the AES encryption (by a dummy process), I could not get it's pid in logfile. Why is this hooking not working?
*P.S.: Following is the declaration of AES_encrypt (in aes.h of OpenSSL) function that is called to perform the AES encryption.
void AES_encrypt(const unsigned char *in, unsigned char *out,
const AES_KEY *key)

Does anyone know if ios4 supports unix domain sockets?

The following works without error on OSX 10.6, but fails in the iphone simulator using SDK 4.1
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/tcp.h>
#include <sys/un.h>
#include <string.h>
int main(void) {
int sock = socket(AF_UNIX, SOCK_DGRAM, 0);
struct sockaddr_un sock_addr;
memset(&sock_addr, 0, sizeof(struct sockaddr_un));
sock_addr.sun_family = AF_UNIX;
strcpy(sock_addr.sun_path, "/tmp/sock");
int err = bind(sock, (struct sockaddr*)&sock_addr, sizeof(struct sockaddr_un));
if(err == -1) {
perror("bind: ");
}
}
Error is "Address family not supported by protocol family"
Any ideas?
You really need to check sock already - most likely, the socket creation is what failed already.
My guess is that AF_UNIX/SOCK_DGRAM is not supported; try SOCK_STREAM instead.