Tag Archives: C language

Python calls C to generate so library and reports an error: undefined symbol

  After using C + + to implement some algorithm functions, there is an error when calling Python:

AttributeError: /..../libHessian4Nii.so: undefined symbol: callVesselSegNii

    According to Du Niang, it is because the function name will be renamed in the C + + compiled file (which is convenient to realize the overload function), so the function name cannot be found when calling the script.

The solution is to use   extern “C”   Just enclose the header file to be exposed. Examples are as follows:

extern "C"{

  int callVesselSegNii(char* oriNiiFile, char* maskNiiFile, char* save_path);
 
}

After recompilation, call the normal!!!!

Keil Compile Error: ..\OBJ\USART.axf: error: L6002U: Could not open file ..\obj\sys.o: No such file or directory

This is not the first time that this problem has occurred. When I go to the Internet for help, it mostly refers to the problem of environment variables. After I change it, I find that keil flashes back. When I see someone saying that it is impossible to generate. O files, I add them manually, but my intuition tells me that this is the most correct choice. After consulting the data, I find that the following problems occur.

One reason for the error is that your computer user name is Chinese, which is the problem of environment variables, but I did not report an error when running the routine, indicating that there is no problem with my environment;

Another reason is that there was a low version of keil software installed before, and the registry was not deleted after uninstallation. At this time, just delete it.

My problem is that I didn’t pay attention when creating a new project. I copied the routine directly, and then added the file manually, resulting in an existing. O file. At this time, I compiled it again, resulting in a problem. Because preprocessing, compilation, assembly and linking are indispensable, the. O file is generated in the assembly stage. If it already exists, it will trigger the error report. I would like to remind you that the new project should not be as easy as me, but step by step

Could not find method causes verifyerror, which in turn causes crash

On Android 5.0 and below, sometimes the course not find method causes verifyerror, which leads to crash. The writing method is as follows:

 

As shown in the figure above, calling static method test1 on Android 4.4 mobile phone will report the following error:

  10-28 16:02:40.913 2792-2792/com.example.myapplication I/dalvikvm: Could not find method com.bumptech.glide.Glide.with, referenced from method com.example.myapplication.TestKt.test2
10-28 16:02:40.913 2792-2792/com.example.myapplication W/dalvikvm: VFY: unable to resolve static method 4: Lcom/bumptech/glide/Glide;. with (Landroid/content/Context;)Lcom/bumptech/glide/RequestManager;

The reason is that Android 5 is a delvikvm virtual machine before, and then other static methods will be loaded when the static method is invoked. So when the test1 is called, the Glide in test2 will be loaded, but at this time it will be found that the with method can not find the method, so the problem can not be found, which will lead to the explosion of VerifyError error.

Solution: Although compileonly is intentionally written above, brand differentiation may occur on mobile phones of different brands, and then some brands do not rely on relevant classes to report errors. Therefore, you can change the places in test2 that need to be called to the dynamic loading mode, that is, the reflection mode, so that test2 will be loaded when test1 is called, However, the reflection method must be called to load the class, that is, the problem of calling test1 and then failing to find the method will not occur.

Examples of solutions are as follows:

public fun test2(context:Context) {
    try {
        Log.e("Test", "test1")
        val clazz = Class.forName("com.bumptech.glide.Glide")
        val getMethod: Method = clazz.getMethod("with", context.javaClass)
        getMethod.invoke(null, context)
    } catch (e: Exception) {
        Log.e("Test","test1 e "+e.message)
    }
}

Note: the above error is OK on Android 5.0 and above phones. It should be the difference between dalvikvm and artvm

srs Error: demux SPS/PPS : avc decode sequence header

SRS reports errors as follows:

[31m[2021-10-23 17:43:55.682][Error][31374][5ns94367][4] serve error
code=3001 : service cycle : rtmp: stream service : rtmp: receive
thread : handle publish message : rtmp: consume message : rtmp:
consume video : meta update video : demux SPS/PPS : avc decode
sequence header

This error means that SRS cannot obtain SPS and PPS information when receiving the code stream.
then select to disconnect from the streaming end. At this time, if the streaming end continues to push the stream, av_interleaved_write_frame (…) will report – 32, and the print log is:

broken pipe

The following encoder parameters need to be set:

if(octx->oformat->flags & AVFMT_GLOBALHEADER)
{
	printf("set video GLOBAL_HEADER\n");
	enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
octx Represents the output context

Explain PPS and SPS, two-byte areas in the code stream, which are very important for decoding. If they are not found, decoding will
fail because they store the parameters set by the encoder, such as the height and width of the video, the sampling rate of the audio, the number of channels, etc
explain the meaning of the above code segment. It will detect the encapsulation format of the output context to determine whether AV is set_CODEC_FLAG_GLOBAL_HEADER.
The function of the AV_CODEC_FLAG_GLOBAL_header flag is to add PPS and SPS in front of each keyframe from the original encoding to the byte area of extradate. Then, when decoding, you have to read PPS and SPS from extradate and put them in front of each keyframe.

Hadoop cluster: about course not obtain block: error reporting

Hadoop cluster: about course not obtain block: error reporting

When accessing HDFS, you encounter the above problems,
it is a node problem:
then check whether the firewall is closed, whether the datanode is started, and whether the data block is damaged:
check and find out that the second problem is the second problem. Then restart Hadoop daemon start datanode on the corresponding host on the command line, JPS to see that it has been started,
then try to execute the code to see if there is an error,
Similarly,
datanodes often hang up automatically,

go to the web (host: 9870)
find that other nodes are not really started in live node
OK
Restart,
reformat
find the HDFS data storage path in the configuration file:

delete $Hadoop from all nodes_ Home%/data/DFs/data/current
then restart the Hadoop cluster (turn off the security mode% hadoop_home% $bin/HDFS dfsadmin – safemode leave)
you can also see that the data has been deleted on the web side,
the landlord found that there are still previous data directories, but the content has been lost
you need to delete these damaged data blocks as well
execute HDFS fsck

View the data block of the mission

hdfs fsck

-Delete deletes a damaged data block

Then upload the data again and execute it again.

How to Solve Fatal error stdatomic in C/C++ Compilation

Fatal error: stdatomic. H: no such file or directory

Under Linux, errors are reported when compiling the source code using gcc

fatal error: stdatomic.h: No such file or directory
 #include <stdatomic.h>
                       ^
compilation terminated.

The reason is that the version of GCC 4.8 is too low and requires a higher version of GCC. How to safely upgrade the GCC version?

The devtoolset package can be installed through CentOS release SCL source

yum install centos-release-scl
yum install devtoolset-8

Or add your own source to install it (I’ll take centos7 as an example)

vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
#mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

Activate the GCC version to make it effective

scl enable devtoolset-8 bash

or

source /opt/rh/devtoolset-8/enable

At this time, you can see through the GCC — version command that the GCC version has changed to 8.X.x. it is worth noting that this only takes effect in the current bash. If it needs to take effect permanently, you can add environment variables yourself.

How to Solve Fopen bus error

Bus error (core dumped) occurs in my program, and the error is locked in the fopen part of the code

void dipget(int icdp, int nti, float *dip, char * tanpath)
{
  FILE * dfile;
  char *filename;

  printf("Choose %d from %s\n",icdp, tanpath);
  sprintf(filename, "%s%d.x.dat",tanpath, icdp);
  printf("Open file: %s \n", filename);

  if((dfile = fopen(filename,"rb"))==NULL) // Bus error
  {
    printf("\n Open %s File error\n",filename);
    exit(EXIT_FAILURE);
  }
  fread(dip, sizeof(float), nti, dfile);
  fclose(dfile);
}

Here, you only need to make one step of modification to solve the problem. The reason is very simple. Before using sprintf, you need to allocate a buffer space to it

  char *filename;
  Change to
  char filename[200];

[Solved] Vs error: link: fatal error lnk1168: unable to open for writing

Project scenario:

use VS to program in C language and generate solution report – > Execution error


Problem Description:

error: link: fatal error lnk1168: unable to open C:\users\86139\desktop\plan\notes\C\tryproject \ debug\tryproject.exe for writing

#include <stdio.h>
#include "math.h"//Since the library function sqrt() is to be used

int main(){
	//Requirement: determine if the quadratic function has real roots, and output if it does?
	double a,b,c,disc,x1,x2,p,q;//declare variables
	printf("Please enter the values of a,b,c respectively: \n");
	scanf("%lf%lf%lf",&a,&b,&c);//enter the value and store it at address a,b,c
	disc=b*b-4*a*c;//discriminant
	if(disc<0){
		printf("This equation has no real roots!!!");
	}else{//disc>=0
		p=-b/(2.0*a);
		q=sqrt(disc)/(2.0*a);
		x1=p+q;
		x2=p-q;
		printf("此方程的两实根为:\nx1=%7.2f\nx2=%7.6f\n",x1,x2);
	}
}

Cause analysis:

the process may already exist, so it cannot be opened and run


Solution:

just finish the process of the program. You can open “process manager” (Task Manager), Ctrl + Alt + delete, find the corresponding process, and right-click to finish.

When C language refers to a user-defined type as a parameter, an error segmentation fault is reported

Problem Description:

In the data structure operation, a function to initialize the table is written:


#define InitSize 100
#define ElemType int

typedef struct {
    ElemType* list;
    int len;
    int size;
} sql_;


int sql_init(sql_ *head) {
    (*head).list = (ElemType*)malloc(InitSize*sizeof(ElemType));
    (*head).len = 0;
    (*head).size = InitSize;

    return 1;
}

int main() {
    sql_ L1;
    sql_init(&L1);

    sql_*L2;
    sql_init(L2);

    system("pause");
}

However, an error is reported at runtime: segmentation fault

  After entering the debugging interface, it is found that L1 has been initialized successfully, but there is a problem when it comes to L2. What is the difference between L1 and L2 initialization codes?

Analyze the problem:

    sql_ L1;
    sql_init(&L1);

    sql_*L2;
    sql_init(L2);

It can be seen that L1 is declared as SQL_ Type; L2 is declared as SQL*_ Type.

There is no warning in vscode, but there is a warning and error in vs2019, and it can not even be compiled. So what’s the reason?

Through network retrieval, we get such an article: int * a in C + +; int & a; int & * a; int * & a_ Tianya Mingyue Dao blog – CSDN blog

Inspired by the quoted concepts mentioned in the article, we made the following attempts:

sql_ L;
    sql_*L2 = &L;
    sql_init(L2);

  After such processing, the initialization can be completed successfully. Therefore, the following guess is made:

When defining a macro type, only SQL is declared_ Type, but for SQL_* The type is not declared, so it is declared in main   sql_  *  L1; The compiler can’t find the prototype, so it can’t reference SQL when declaring parameters_* Type, so vs the more stringent compiler found this problem and told L2 that memory could not be allocated.

resolvent:

Using predefined SQL_ Type declaration, use its reference when parameters need to be passed & amp; L as SQL_* Arguments of type, that is, the method of initializing L1 mentioned earlier:

    sql_ L1;
    sql_init(&L1);

[Error] invalid operands to binary ^ (have ‘double‘ and ‘float‘)

C. It cannot be used directly in C + +^

In C and C + +, you can’t use ^ to represent the index, only * can be used. If you want to use the index, you can only establish a cycle to multiply multiple times or write multiple directly by multiplication. The following is my code. The comment part is the original index form, and the above error will be reported.

Or reference mathematical functions and add #include & lt; math.h>;

Pow (x, y) is used to solve the Y power of X;

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	double p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;
	p1=p0*(1+r1)*(1+r1)*(1+r1)*(1+r1)*(1+r1)*(1+r1);
	//p1=p0*(1+r1)^6;
	p2=p0*(1+r2)*(1+r2)*(1+r2);
	//p2=p0*(1+r2)^3;
	p3=p0*(1+r3)*(1+r3);
	//p3=p0*(1+r3)^2;
	double x=1,y=2,p;
	p = pow(x+1,y);  //Find the yth power of x+1, which is the exponent 
	printf("The square of 1+1 is %lf",p);
	printf("deposit 1 year %lf, deposit 2 years %lf, deposit 3 years %lf",p1,p2,p3);
	return 0;
}

error: field ‘XXX’ declared as a function [How to Solve]

Problem description

Some time ago, I started a small smart home project to practice my hand. I encountered this problem when compiling

Compilation error:

reason:

The function pointer in the structure element is incorrectly defined

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <wiringSerial.h>

struct Command{
        char cmdName[128];
        char cmd[32];
        int (*init)();		//int init();
        int (*getCmd)(struct Command *voice);	//int getCmd(struct Command *voice);
        char log[1024];
        int fd;
        struct Command *next;
};