libyahoo Segmentation fault [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wrote this code:
#include <libyahoo2/yahoo2.h>
#include <libyahoo2/yahoo2_callbacks.h>
int main() {
int id ;
char username[255] = "slam";
char password[255] = "ss" ;
id = yahoo_init(username, password);
enum yahoo_status mYahoo ;
mYahoo = YAHOO_STATUS_AVAILABLE ;
yahoo_login(id , mYahoo );
return 0;
}
Compile it, gcc -l yahoo2 y.c -o yahoo and run it with ./yahoo gives me a error: Segmentation fault
(gdb) run
Program received signal SIGSEGV, Segmentation fault.
0x001379b1 in yahoo_login (id=1, initial=0) at libyahoo2.c:1735
line 1735 code is:
tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id,
host, yss->pager_port, yahoo_connected, ccd, 0);
and see this :
(gdb) list YAHOO_CALLBACK
Function "YAHOO_CALLBACK" not defined.
How do I debug this?

How do I debug this?
Execute these commands:
(gdb) print yd->client_id
(gdb) print yss->pager_port
My guess would be that one or both of the above commands will fail, because yd or yss is NULL.
If so, the problem is earlier in libyahoo2.c, and it (apparently) doesn't check for errors properly.
The reason you can't list YAHOO_CALLBACK is most likely that it is a macro. Look in libyahoo2/yahoo2_callbacks.h -- it's very likely to be defined there.
Also, your link command line:
gcc -l yahoo2 y.c -o yahoo
is totally bogus. Correct command line should be:
gcc y.c -o yahoo -lyahoo2
You may want to read this explanation to understand why order of sources and libraries on command line matters.

Related

How to find executing functions in between two function in C Programming [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I know two functions func_1 and func_5, but there are some functions in between func_1 and func_5 for sure which I don't know what are those functions now my question is my program is hitting func_1 but not reaching to funct_5 somewhere between my program is getting crash when I ran gdb, but I didn't have any backtrace details since my program is getting stopped.
Now how can I know where and in which function it is getting crashed, I doubt in between those two functions func_1 and func_5 some function is creating that crash.
[Inferior 1 (process 23939) exited with code 01]
(gdb) bt
No stack.
Please can anyone tell me how to approach this?
Since you use gdb, rbreak and backtrace can help.
An example:
/* demo.c */
#include <stdio.h>
void fn1(void) { puts("Hello"); }
void fn2(void) { fn1(); }
void fn3(void) { fn2(); }
int main(void)
{
fn3();
return 0;
}
Compile with -g flag on:
gcc -std=c11 -Wall -pedantic -g -o demo demo.c
Create a script to automatize the task, call it trace.gdb (the name is not important) with the following contents:
set pagination off
rbreak demo.c:.
command
silent
backtrace 1
continue
end
run
Now run the command:
gdb -quiet -command=trace.gdb ./demo
The output is:
Reading symbols from ./demo...done.
Breakpoint 1 at 0x40053a: file demo.c, line 3.
void fn1(void);
Breakpoint 2 at 0x40054b: file demo.c, line 4.
void fn2(void);
Breakpoint 3 at 0x400556: file demo.c, line 5.
void fn3(void);
Breakpoint 4 at 0x400561: file demo.c, line 9.
int main(void);
#0 main () at demo.c:9
#0 fn3 () at demo.c:5
#0 fn2 () at demo.c:4
#0 fn1 () at demo.c:3
Hello

How to write a C/C++ wrapper program in Linux that is fully transparent [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Note: This is not a question to ask for a program, It asks about some tech details, see the question bellow first.
I need to write a wrapper program in C/C++ for an existing program. I know we need to use exec/fork/system and pass through the parameters then return the result of the program.
The question is, how to ensure that both the invoker program(that invoke the wrapper) and the wrapped program work exactly like before (ignore timing differences). There maybe subtle things like environment parameters to deal with. fork/system/exec, which to use? Are they enough? Are there other factors to consider?
Let's say you have the following original program:
foo.sh
#!/bin/bash
echo "Called with: ${#}"
exit 23
Make it executable:
$ chmod +x foo.sh
Now the wrapper in C:
wrapper.c
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
printf("Executing wrapper code\n");
/* do something ... */
printf("Executing original program\n");
if(execv("./foo.sh", argv) == -1) {
printf("Failed to execute original program: %s\n", strerror(errno));
return -1;
}
}
Run it:
$ gcc wrapper.c
$ ./a.out --foo -b "ar"
Executing wrapper code
Executing original program
Called with: --foo -b ar
$ echo $?
23

Below C code runs on Fedora, however on RaspberryPi 1, gives a segmentation fault [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to compile the below C code on Fedora 23 computer (gcc version 5.3.1 20151207 (Red Hat 5.3.1-2) (GCC)) and it gives no errors. And program runs.
However when I'm compile the same code on Raspberry Pi 1 Model B+ (gcc version 4.9.2 (Raspbian 4.9.2-10) ), compiler gives no errors but crashes when running.Can someone figure out, where's the issue?
Debug info also attached.
/* Compile with
* gcc -lm opencv_video_isolated.c -o ooopencv_video_isolated `pkg-config --cflags --libs opencv`
*/
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#include <X11/Xlib.h>
int main()
{
CvCapture* capture;
capture = cvCreateCameraCapture(0);
IplImage* frame;
/* Capture a single frame from the video stream */
frame = cvQueryFrame( capture );
double ab = frame->depth;
double ac = frame->width;
double ad = frame->height;
return 0;
}
Also I've pasted the GDB output on Raspberry Pi.
(gdb) file opencv_video_isolated
Reading symbols from opencv_video_isolated...done.
(gdb) run
Starting program: /home/.../src/opencv_video_isolated
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
[New Thread 0xb30ec270 (LWP 1523)]
Program received signal SIGSEGV, Segmentation fault.
0x00012718 in main () at opencv_video_isolated.c:22
22 double ab = frame->depth;
(gdb) backtrace
#0 0x00012718 in main () at opencv_video_isolated.c:22
(gdb)
Program received signal SIGSEGV, Segmentation fault.
You'll want to print frame. Most likely it's NULL. Then you'll need to figure out what preconditions of cvQueryFrame or cvCreateCameraCapture you've violated.

Permission denied when trying to run C program in terminal [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm completely new to programming. I'm actually learning from a Harvard class on iTunes U. When trying to code along side the instructor I've ran into a problem. I can't run my .c program in terminal. I've tried the sudo commands, and I've searched with Google and I can't seem to find an answer, probably because I'm so new to programming. It's probably something I've overlooked or I just don't understand yet.
#include <stdio.h>
int
main(void)
{
printf("temperature in f: ");
float f = GetFloat();
float c=f / 9.0 * (f-32);
Printf("%. if F = %. if c\n", f, c)
I'm using Sublime text editor on a MacBook with Mac OS X Yosemite (10.10.x).
Your compiler should have warn you about some errors:
// string.c
#include <stdio.h>
int main(void) // There must be a return statement
{
printf("temperature in f: ");
float f = GetFloat();
float c = f / 9.0 * (f-32);
printf("%f if F = %f if c\n", f, c); // Missing ';' is the most common syntax error
return 0; // Here is the return
} // Do not forget to close your brackets
When you do:
gcc string.c -o myprogram
It will tell you what is wrong in your program. Once you have fixed all the errors you can run the program with:
./myprogram
Understand that you cannot run a C-file: the .c contains human-readable instructions for the machine. You have to compile it, i.e. translate it into a language that your computer will understand : it is roughly your compiled myprogram (and you do not want to open it to look what it contains, it will burn your eyes :p).
Just adding to the below answer your compiler should throw the below error also:
undefined reference to `Printf'
check case of your printf()

User input C programming [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to run a C program that requires the user input.
The program is supposed to prompt the user to enter certain words and I am supposed to search for those words in a data structure.
so the command line is supposed to look like this:
prompt>
the user will enter multiple words to search and I need access to each one of those words separately. AFter the program is done executing on those words, the program needs to restart and keep running until the user types in "quit" in the prompt.
Ex:
prompt> ..... (program will run based on the words input)
prompt> .....
prompt> .....
prompt> quit
I dont know how to prompt for user input in C, can anyone help with this?
Thanks in advance.
1) vi hello.c:
#include <stdio.h>
#define MAX_LEN 80
int
main (int argc, char *argv[])
{
char a_word[MAX_LEN];
printf ("Enter a word: ");
scanf ("%s", a_word);
printf ("You entered: %s\n", a_word);
return 0;
}
2) gcc -G -Wall -pedantic -o hello hello.c
3) ./hello
NOTE:
The syntax will be different depending on your platform and compiler.
Here's another link:
http://www.codingunit.com/c-tutorial-first-c-program-hello-world
This might help
http://en.wikibooks.org/wiki/C_Programming/Simple_input_and_output
basically scanf

Resources