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 |
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. |
Quote:
Quote:
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? |
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 |
To compile your first program, I recommend a Hello World. Simple, guaranteed to work with GCC and takes 2 minutes.
Code:
#include <iostream> Code:
gcc -i hello.c -o hello Code:
cd <PROJECT DIRECTORY> |
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" 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> Being that said, to compile a simple program in C you would do Code:
gcc -o foo.o foo.c Code:
gcc -o foo.o -c foo.c 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. |
All times are GMT -5. The time now is 12:30 PM. |