LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-10-2009, 12:08 AM   #1
Mihir V Patankar
LQ Newbie
 
Registered: May 2009
Posts: 8

Rep: Reputation: 0
Question compiling c programs on Linux


Hi

I recently copied a few .so files using ftp from a sun sparc machine on to my linux machine (i686 i686 i386 GNU/Linux).

When i tried to reload the radius application residing on the linux machine i get the following error:-

[ //localhost ]
LicenseInfo = AR-Standard 4.0
AR-Prepaid 4.0
AR-CPU 4.0
Radius/
Administrators/

--> reload

Reloading Server 'Radius'...
310 Command failed
Server 'Radius' failed to start
The server wrote the following errors to the log file:
Configuration Unable to load shared library '/opt/CSCOar/scripts/radius/rex/librexcisco.so' specified by the script /Radius/Scripts/CiscoOutgoingScript. The error message is: /opt/CSCOar/scripts/radius/rex/librexcisco.so: ELF file data encoding not little-endian

I started to get this error after i copied those .so files

Will i need to compile the c programs on linux indepedently?

If that is the case then how do i go about compiling the c programs on my linux machine?

Thanks!

Mihir V Patankar
 
Old 06-10-2009, 12:15 AM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Well, Solaris libraries are not going to work under Linux, it's a completely different operating system.
Your best bet to install new software under Linux is to download a package designed for your distribution from a repository and use a package manager to install it.
If you definitely want to compile from source, you download the source and read the instructions included by the programmers on how to build their software. Usually, you just unpack the source and run
./configure
make
su
make install
but for different programs things may vary.You'll need a compiler, gcc and some other things. To install them, you again need to get them from you distribution repository or from the installation media.
 
Old 06-10-2009, 01:02 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,043

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Quote:
Originally Posted by Uncle_Theodore View Post
Well, Solaris libraries are not going to work under Linux, it's a completely different operating system.
Not only that, but sparc is also a completely different animal than x86. Not only the two OSes are incompatible at binary level, but they have also been compiled to run on different hardware. Even if he was running linux on the sparc machine, those binaries wouldn't ever work on the x86 one.



Quote:
Originally Posted by Mihir V Patankar View Post
Hi

I recently copied a few .so files using ftp from a sun sparc machine on to my linux machine (i686 i686 i386 GNU/Linux).
Why? What are those .so files? Explain a bit what you are trying to do. Are you overwriting already existing linux .so files with the sun sparc ones? Are those .so files maybe plugins or extensions of any kind for radius?

For what I can deduct from the output, you already have radius running on linux, don't you? In that case, what what are you trying to add or change?
 
Old 06-16-2009, 02:54 AM   #4
Mihir V Patankar
LQ Newbie
 
Registered: May 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Question

Hi,
I copied the following c program from our sun sparc machine to the linux machine (i686 i686 i386 GNU/Linux).I want to compile and run the following c script on the Linux machine.I want to know the steps for compliling and running the c program

#include <string.h>
#include <stdio.h>
#include <fnmatch.h>
#include <stdlib.h>
#include <ctype.h>
#include "rex.h"
#include <time.h>
#include <sys/timeb.h>
#include <arpa/inet.h>
#include "bitstring.h"
#include <mysql.h>


int REXAPI JustTesting( int iScriptingPoint,
rex_AttributeDictionary_t* pRequest,
rex_AttributeDictionary_t* pResponse,
rex_EnvironmentDictionary_t* pEnviron )
{
const char* framedip;

if( strcmp( pEnviron->get( pEnviron, "Request-Type" ),
"Access-Request" ) != 0 &&
strcmp( pEnviron->get( pEnviron, "Request-Type" ),
"Accounting-Request" ) != 0)
{
pEnviron->trace( pEnviron, 10, "ExecRealmRule exiting because packet "
"is not the right request type" );
return REX_OK;
}

if(!(pRequest->containsKey( pRequest, "Framed-IP-Address" ))){
pEnviron->trace( pEnviron, 10, "No Framed IP");
return REX_ERROR;
}else{
framedip = pRequest->get( pRequest, "Framed-IP-Address", 0, 0 );
pEnviron->trace( pEnviron, 10, "Framed IP is %s",framedip);
}

/* cbUserName = pszUserName ? strlen( pszUserName ) : 0; */
pEnviron->trace( pEnviron, 10, "IPaddress is: %s", framedip);
/* Mysql starts here */
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *queryfinal;
char *location_name, *location_id;

char *server = "127.0.0.1";
char *user = "root";
char *password = "*****";
char *database = "mihir";
/* char *querystr = "SELECT * FROM location WHERE ipaddress = \"10.10.10.23\""; */
char *querystr = "SELECT * FROM location WHERE ipaddress = \"";
pEnviron->trace( pEnviron, 10, "STRCATING %s and %s",querystr,framedip);
queryfinal = (char *)calloc(strlen(querystr) + strlen(framedip) + 2, sizeof(char));
strcat (queryfinal,querystr);
strcat (queryfinal,framedip);
strcat (queryfinal,"\"");
pEnviron->trace( pEnviron, 10, "MYSQL INIT TRY....");
conn = mysql_init(NULL);
mysql_real_connect(conn, server,user, password, database, 0, NULL, 0);
pEnviron->trace( pEnviron, 10, "Connected to MySQL");
pEnviron->trace( pEnviron, 10, "Trying query-> %s",queryfinal);
if(mysql_query(conn, queryfinal)){
pEnviron->trace( pEnviron, 10, "Query Failed");
}else{
pEnviron->trace( pEnviron, 10, "Query OK");
}
res = mysql_store_result(conn);
if(mysql_num_rows(res) > 0){
pEnviron->trace( pEnviron, 10, "Record Found");
}else{
pEnviron->trace( pEnviron, 10, "No Record Found");
return REX_ERROR;
}
pEnviron->trace( pEnviron, 10, "Exec query-> %s",queryfinal);
pEnviron->trace( pEnviron, 10, "Query Result Is %d",res);
while ((row = mysql_fetch_row(res)) != NULL){
pEnviron->trace( pEnviron, 10, "Output -> %s %s %s\n", row[0], row[1], row[2]);
pEnviron->trace( pEnviron, 10, "Trying calloc");
location_name = (char *)calloc(strlen(row[1]),sizeof(char));
location_id = (char *)calloc(strlen(row[2]),sizeof(char));
pEnviron->trace( pEnviron, 10, "Trying strcpy");
strcpy (location_name,row[1]);
strcpy (location_id,row[2]);
}

pEnviron->trace( pEnviron, 10, "LocationID: %s, LocationName: %s", location_id,location_name);
pRequest->put( pRequest, "WISPr-Location-Name",location_name , REX_REPLACE );
pRequest->put( pRequest, "WISPr-Location-Id",location_id , REX_REPLACE );


/* Mysql ENDs here */
return REX_OK;


Thanks!

Mihir V Patankar
 
Old 06-16-2009, 03:13 AM   #5
Mentalikryst
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Rep: Reputation: 0
To compile your first program, I recommend a Hello World. Simple, guaranteed to work with GCC and takes 2 minutes.

Code:
#include <iostream>

int main()
{
   std::cout << "Hello World!";
   return 0;
}
Now open up a terminal and type:

Code:
gcc -i hello.c -o hello
For multiple file projects, put all of the files into a single folder and then install qmake and then go through this process to build the application:

Code:
cd <PROJECT DIRECTORY>
qmake -project
qmake
make
 
Old 06-16-2009, 04:47 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,043

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Mihir V Patankar, I have no idea what the code is about, haven't looked deeply into it, however I warn you that it's not a standalone program so it won't be of any use without the main module whatever it is.

Besides that, these two lines:

Code:
#include "rex.h"
...
#include "bitstring.h"
Mean that this .h files are going to be searched for in the same directory where this source that you pasted lives. Which in turn means that the project has many source files that you haven't even considered. Unless you have all the pieces you are not going to be able to build this thing.

However, at least in linux, glibc has a rex.h, so maybe you could change the rex.h line with this one:

Code:
#include <rpcsvc/rex.h>
Can't seem to remember about bitstring.h right now and maybe it's something specific to other *nixes.



Being that said, to compile a simple program in C you would do

Code:
gcc -o foo.o foo.c
When it's not meant to be a standalone program (this is the case) you only want to compile, and not link.

Code:
gcc -o foo.o -c foo.c
But for anything that's something more than a simple c file with a .h you should use a Makefile and the make tool (well, or qmake, cmake or whatever you prefer for that concrete case).

Mentalikryst, you are threating it as C, but what you wrote is C++. I am not going into the debate about why it is a very bad thing to do so, there's already enough of that on the net. I just write this here so any newcomer that sees that knows that, well, it's not technically correct. Don't use .c for c++ files, and compile them using g++. AmbigUity is never a good thing when programming. Besides that, the file that the other guy posted is C.

Last edited by i92guboj; 06-16-2009 at 04:52 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
the process of compiling c/c++ programs in linux iochinome Linux - Newbie 5 03-31-2009 10:13 PM
Compiling programs for Windows on Linux bugscripts Linux - Software 24 03-10-2008 10:27 PM
why is compiling source programs under linux such a headache? guy24x Linux - Software 21 07-28-2005 07:04 AM
Compiling Programs Jabber63 Linux - Software 3 08-06-2003 03:58 AM


All times are GMT -5. The time now is 11:51 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration