begin process at 2012 05 30 09:25:53
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C++ & C++ .NET

 > 

Linux

 > 

Autre

 > 

Shared Library


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Shared Library

lundi 13 novembre 2006 à 16:34:14 | Shared Library

omarlahlou

Bonjour tout le monde,

 

Je voulais créer une librairie partagée (Shared Library) en C++ sous Linux (Fedora 6) pour un petit projet HelloWord qui appelle une simple fonction (voir le code ci-dessous).

J'ai suivi les étapes suivantes pour créer la librairie:

 

gcc -Wall -fPIC -c *.c

gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0   *.o

mv libctest.so.1.0 /opt/lib

ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so

ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so.1

gcc -Wall -L/opt/lib Hello.cpp -lctest -o Hello

 

a la fin je reçois le massage suivant :

 

/tmp/cc900iU4.o: In function `__static_initialization_and_destruction_0(int, int)':

Hello.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'

/tmp/cc900iU4.o: In function `__tcf_0':

Hello.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'

/tmp/cc900iU4.o: In function `main':

Hello.cpp:(.text+0x8e): undefined reference to `std::cout'

Hello.cpp:(.text+0x93): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

Hello.cpp:(.text+0x9b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'

Hello.cpp:(.text+0xa3): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'

Hello.cpp:(.text+0xb2): undefined reference to `std::cout'

Hello.cpp:(.text+0xb7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

Hello.cpp:(.text+0xbf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'

Hello.cpp:(.text+0xc7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'

Hello.cpp:(.text+0xd5): undefined reference to `std::cin'

Hello.cpp:(.text+0xda): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'

Hello.cpp:(.text+0xe9): undefined reference to `std::cout'

Hello.cpp:(.text+0xee): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

Hello.cpp:(.text+0xf6): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'

Hello.cpp:(.text+0xfe): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'

Hello.cpp:(.text+0x10c): undefined reference to `std::cin'

Hello.cpp:(.text+0x111): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'

Hello.cpp:(.text+0x120): undefined reference to `std::cout'

Hello.cpp:(.text+0x125): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

Hello.cpp:(.text+0x12d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'

Hello.cpp:(.text+0x135): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'

Hello.cpp:(.text+0x158): undefined reference to `std::cout'

Hello.cpp:(.text+0x15d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'

Hello.cpp:(.text+0x165): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'

Hello.cpp:(.text+0x16d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'

/tmp/cc900iU4.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'

collect2: ld returned 1 exit status

 

 

Hello.cpp

 

#include <iostream>

#include "Function.h"

 

using namespace std;

 

int main(int argc, char *argv[])

{

            int a,b,c;

            cout << "Hello Dialexia" << endl;

            cout << "Enter a:" << endl;

            cin >> a;

            cout << "Enter b:" << endl;

            cin >> b;

            cout << "a + b =" << endl;

            c = sum(a,b);

            cout << c << endl;

            return 0;

}

 

 

Function.cpp

 

#include "Function.h"

 

int sum( int a, int b) {

return a+b ;

}

 

 

 

Function.h

 

#ifndef FUNCTION_

#define FUNCTION_

 

int sum( int a, int b);

 

#endif /*FUNCTION_*/

 


Merci Beaucoup d'avance

lundi 13 novembre 2006 à 18:54:50 | Re : Shared Library

ShareVB

Réponse acceptée !
salut,

pour compiler ton Hello.cpp utilise g++ à la place de gcc...on compile du C avec GCC et du C++ avec G++...

ShareVB


Cette discussion est classée dans : basic, cpp, std, hello, ostream


Répondre à ce message

Sujets en rapport avec ce message

Erreur de linkage - de vc++98 a vc++2008 [ par pepsidrinker ] Bonjour a tous, merci de lire ce post. Jai un petit probleme de linkage: Jai un programme c++ (pure et dure, pas de MFC ni de .NET), que jai developpe class template ;surcharge operator << >> [ par lui88 ] Bonjour , aprés plusieurs forum je n'arrive toujours pas a reglé mon probleme le programme fonctionnais sur Visual V6 je le migre sous visual studio 2 symbole externe non résolu [ par informatixa ] Voila mon erreur et, je ces pas d'ou sa peut venir.Login.obj : error LNK2001: symbole externe non résolu "public: __thiscall ConfigFile::ConfigFile(cl Programmer pour les erreurs [ par kml404 ] bonjour [b]exp;[/b] par [u]Application console Win32[/u] j'ai fait supprimé ce mot "stdafx.h", nouveau ajouté "windows.h" apres, fait les augman Segfault bizarre sur un "cout" [ par Thunder255 ] Bonjour à tous, Voilà je fais face à un problème assez bizarre : [code=cpp]int main() { Graph g = Graph(5, 0.5); //g étant de type list > //rep ifstream [ par johnASP ] Bonjour! J'aurais voulu savoir si s'était possible de passer une variable en paramétre d'un "ifstream()"? Car je voudrais lire un fichier dont le ch template rendre friend un operator<< [ par littlenemo ] Hello world !!Un petit merci a tout ce qui me lirons et peut etre un grand a celui qui me donne ma reponce.Alors je vous mets dans le bain:Je doit cod Template avec surcharge d'opérateurs [ par benjiiim94 ] Bonjour,J'essaie déséspéremment de créer une petite classe pour me familiariser avec les templates. Non sans mal j'ai obtenu un résultat pas mal jusqu ant script error link g++ [ par fmazoue ] I need help !!!I have error with linker I try to add but the script bug and do nothing ...but if I try directly in cmd this it's ok : g++ -o Util.dll Problème de linkage [ par huguette45 ] Salut,je suis entrain de faire un projet en C++ (utilisant visual C++ 2005 Express) et j'ai quelques problèmes lors du linkage en fin de compilation..


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 2,090 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales