LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2017, 11:11 PM   #1
david1984ba
LQ Newbie
 
Registered: Mar 2017
Posts: 2

Rep: Reputation: Disabled
Problems compiling a function of pps_kernel.h


Hello, I need to get a timestamp using a function declared in pps_kernel.h. My code is
Code:
#include <linux/pps_kernel.h>
#include <linux/timekeeping.h>

static inline void pps_get_my_ts(struct pps_event_time *ts)
{
        struct system_time_snapshot snap;

        ktime_get_snapshot(&snap);
        ts->ts_real = ktime_to_timespec64(snap.real);
		#ifdef CONFIG_NTP_PPS
			ts->ts_raw = ktime_to_timespec64(snap.raw);
		#endif 
}

struct pps_event_time {
	#ifdef CONFIG_NTP_PPS
		struct timespec64 ts_raw;
	#endif  CONFIG_NTP_PPS 
		struct timespec64 ts_real;
};

void main()
{
	struct pps_event_time my_ts;
	const struct pps_gpio_device_data *info;	
	pps_get_my_ts(&my_ts);
	printf("%ld -- %ld\n",my_ts.ts_real,my_ts.ts_raw);
	
}
I'm new programer in C and I think my code is correct, so when I tried to compile with gcc thrown many errors

I attach a txt file with the errors.


Can someone explain to me that it is wrong?
 
Old 03-29-2017, 02:11 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Is your program supposed to be a normal userland program? If so, you are not to use any kernel-components.
 
Old 03-29-2017, 06:56 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
If it is supposed to be a kernel space module, then you need to include additional terms within the source and build it differently.

If you need a system time stamp, there are other ways to get one. Some give you seconds and nanoseconds since the epoch, some give you local time, some give you seconds and nanoseconds since the start of the system. It will be helpful for you to explain your needs for the time stamp you wish.

Further, in any future case when you experience a compile problem, it will be helpful to use the -v flag to increase the output for the gcc call, and also show the gcc call as well as the output to the terminal for your compilation attempt. This will give all the flags to readers for their benefit as they evaluate the errors, and also it will show the specific errors for people to review and offer comments about.

Also, not sure but I think you should not have anything except a comment after the #endif term, you can have a comment, but you should not have the CONFIG_NTP_PPS there. That may have changed with C99, I don't know in the past that would've been an error and my practice is to always have nothing, or a comment to link it back to the start of the #if or #ifdef term for my code notes.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in compiling ELF function in qt creator fright Programming 1 01-23-2013 12:09 AM
Compiling 2.6.23: implicit declaration of function ‘scsi_device_cancel’ fof3 Debian 4 12-10-2007 02:16 PM
function in a function in C compiling with gcc joel2001k Programming 5 06-23-2007 08:18 PM
compiling kernel oddity - in function Furlinastis Linux - Software 2 01-06-2007 07:42 PM
Error while compiling kernel 2.4.20-8 (conflicting return type of _exit function) samkraju Red Hat 1 07-01-2006 06:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration