Link errors with libcurl - c++-cli
I include and use libcurl for a project and I get this error
unable to generate p/invoke for "function_declaration" decorated_name; calling convention missing in metadata
and others.
I code with visual studio c++
Ive searched those and I read that there might be a problem with the library, which was compiled from C files. My project is in c++/cli. Do you think that's the problem? what could I do?
#include <curl/curl.h>
#include <curl/easy.h>
that's includes that I'm using
that's the code
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
int written = fwrite(ptr, size, nmemb, (FILE *)stream);
return written;
}
int main()
{
CURL *curl_handle;
static const char *headerfilename = "head.out";
FILE *headerfile;
static const char *bodyfilename = "body.html";
FILE *bodyfile;
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, "http://url");
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
curl_easy_perform(curl_handle);
fclose(headerfile);
fclose(bodyfile);
}
link error LNK2031
link error LNK2019
and others
: error LNK2031: p/invoke konnte nicht für ""extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ)" generiert werden. In den Metadaten fehlt die Aufrufkonvention.
: error LNK2031: p/invoke konnte nicht für ""extern "C" enum CURLFORMcode __clrcall curl_formadd(struct curl_httppost * *,struct curl_httppost * *,...)" (?curl_formadd##$$J0YM?AW4CURLFORMcode##PAPAUcurl_httppost##0ZZ)" generiert werden. In den Metadaten fehlt die Aufrufkonvention.
: error LNK2031: p/invoke konnte nicht für ""extern "C" struct curl_slist * __clrcall curl_slist_append(struct curl_slist *,char const *)" (?curl_slist_append##$$J0YMPAUcurl_slist##PAU1#PBD#Z)" generiert werden. In den Metadaten fehlt die Aufrufkonvention.
: error LNK2031: p/invoke konnte nicht für ""extern "C" enum CURLcode __clrcall curl_easy_perform(void *)" (?curl_easy_perform##$$J0YM?AW4CURLcode##PAX#Z)" generiert werden. In den Metadaten fehlt die Aufrufkonvention.
: error LNK2031: p/invoke konnte nicht für ""extern "C" void __clrcall curl_easy_cleanup(void *)" (?curl_easy_cleanup##$$J0YMXPAX#Z)" generiert werden. In den Metadaten fehlt die Aufrufkonvention.
: error LNK2031: p/invoke konnte nicht für ""extern "C" void * __clrcall curl_easy_init(void)" (?curl_easy_init##$$J0YMPAXXZ)" generiert werden. In den Metadaten fehlt die Aufrufkonvention.
: error LNK2031: p/invoke konnte nicht für ""extern "C" enum CURLcode __clrcall curl_global_init(long)" (?curl_global_init##$$J0YM?AW4CURLcode##J#Z)" generiert werden. In den Metadaten fehlt die Aufrufkonvention.
: error LNK2020: Nicht aufgelöstes Token (0A000016) "extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ).
: error LNK2020: Nicht aufgelöstes Token (0A00001A) "extern "C" enum CURLFORMcode __clrcall curl_formadd(struct curl_httppost * *,struct curl_httppost * *,...)" (?curl_formadd##$$J0YM?AW4CURLFORMcode##PAPAUcurl_httppost##0ZZ).
: error LNK2020: Nicht aufgelöstes Token (0A00001B) "extern "C" enum CURLFORMcode __clrcall curl_formadd(struct curl_httppost * *,struct curl_httppost * *,...)" (?curl_formadd##$$J0YM?AW4CURLFORMcode##PAPAUcurl_httppost##0ZZ).
: error LNK2020: Nicht aufgelöstes Token (0A000020) "extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ).
: error LNK2028: Nicht aufgelöstes Token (0A000021) ""extern "C" struct curl_slist * __clrcall curl_slist_append(struct curl_slist *,char const *)" (?curl_slist_append##$$J0YMPAUcurl_slist##PAU1#PBD#Z)", auf das in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)" verwiesen wird.
: error LNK2028: Nicht aufgelöstes Token (0A000026) ""extern "C" enum CURLcode __clrcall curl_easy_perform(void *)" (?curl_easy_perform##$$J0YM?AW4CURLcode##PAX#Z)", auf das in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)" verwiesen wird.
: error LNK2020: Nicht aufgelöstes Token (0A000027) "extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ).
: error LNK2028: Nicht aufgelöstes Token (0A000028) ""extern "C" void __clrcall curl_easy_cleanup(void *)" (?curl_easy_cleanup##$$J0YMXPAX#Z)", auf das in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)" verwiesen wird.
: error LNK2020: Nicht aufgelöstes Token (0A00002A) "extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ).
: error LNK2020: Nicht aufgelöstes Token (0A00002B) "extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ).
: error LNK2020: Nicht aufgelöstes Token (0A00002C) "extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ).
: error LNK2020: Nicht aufgelöstes Token (0A00002D) "extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ).
: error LNK2028: Nicht aufgelöstes Token (0A00002E) ""extern "C" void * __clrcall curl_easy_init(void)" (?curl_easy_init##$$J0YMPAXXZ)", auf das in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)" verwiesen wird.
: error LNK2028: Nicht aufgelöstes Token (0A00002F) ""extern "C" enum CURLcode __clrcall curl_global_init(long)" (?curl_global_init##$$J0YM?AW4CURLcode##J#Z)", auf das in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)" verwiesen wird.
: error LNK2001: Nicht aufgelöstes externes Symbol ""extern "C" enum CURLFORMcode __clrcall curl_formadd(struct curl_httppost * *,struct curl_httppost * *,...)" (?curl_formadd##$$J0YM?AW4CURLFORMcode##PAPAUcurl_httppost##0ZZ)".
: error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" struct curl_slist * __clrcall curl_slist_append(struct curl_slist *,char const *)" (?curl_slist_append##$$J0YMPAUcurl_slist##PAU1#PBD#Z)" in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)".
: error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" enum CURLcode __clrcall curl_easy_perform(void *)" (?curl_easy_perform##$$J0YM?AW4CURLcode##PAX#Z)" in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)".
: error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" void __clrcall curl_easy_cleanup(void *)" (?curl_easy_cleanup##$$J0YMXPAX#Z)" in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)".
: error LNK2001: Nicht aufgelöstes externes Symbol ""extern "C" enum CURLcode __clrcall curl_easy_setopt(void *,enum CURLoption,...)" (?curl_easy_setopt##$$J0YM?AW4CURLcode##PAXW4CURLoption##ZZ)".
: error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" void * __clrcall curl_easy_init(void)" (?curl_easy_init##$$J0YMPAXXZ)" in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)".
: error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" enum CURLcode __clrcall curl_global_init(long)" (?curl_global_init##$$J0YM?AW4CURLcode##J#Z)" in Funktion ""private: void __clrcall freerice::Form1::backgroundWorker1_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?backgroundWorker1_DoWork#Form1#freerice##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)".
I needed to include some files related to the libcurl now I don't get any linker errors
Related
i wrote an incomplete delay time Program, i need help to continue
package programmierAufgaben_Blatt2; import java.sql.Date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Scanner; public class Aufgabe4 { public static void main(String[] args) throws ParseException { // Here i give which hour Scanner s = new Scanner(System.in); System.out.println("Geben Sie bitte die Stunde ein (00-23): "); int stunden = s.nextInt(); if(stunden < 0 || stunden > 23) { System.out.println("Fehler : Geben Sie bitte eine Stunde im Bereich zwischen 00 und 23. "); } s.nextLine(); // Here i give which Minute System.out.println("Geben Sie bitte die Minuten ein (00-59): "); int minuten = s.nextInt(); if(minuten < 0 || minuten > 59) { System.out.println("Fehler : Geben Sie bitte eine Minute im Bereich zwischen 00 und 59. "); } s.nextLine(); // Here i give the delay time System.out.println("Geben Sie bitte die Verspaetung in Minuten ein (00-59): "); int verspaetung = s.nextInt(); // i dont know what i should code here... // Here is the result System.out.println("Die neue Ankunftszeit ist: " ); } }
Undefined reference to 'yylex' in function 'yyparse()'
Every time I try to fix the issue I get this error. I don't know what I'm doing wrong. Here is my yacc file and my lexx file: HERE IS MY YFILE.Y %{ #include <iostream> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define YYSTYPE double #include "y.tab.h" extern "C" FILE * yyin; extern "C" int yylex(); extern int yyparse(void *); using namespace std; int yyerror(const char* s); %} %token DIGIT CHARACTER OP LEFT_PAR RIGHT_PAR SEMICOLON EQUAL NEWLINE OTHER %union{ char *s; } %% assignment: id EQUAL expression SEMICOLON NEWLINE ; expression: id OP id '{OP id}' | id OP id '{'LEFT_PAR'}' '{'expression'}' '{'RIGHT_PAR'}' NEWLINE | id OP id '{'LEFT_PAR expression'}' '{'RIGHT_PAR'}' NEWLINE ; id: CHARACTER |id CHARACTER |id DIGIT ; %% int yyerror(const char *s) { cout <<"error" << s << endl; return -1; } main (){ FILE *yyin = fopen("ex.txt","r"); yyparse(); fclose(yyin); printf("hi"); return 0; } HERE IS MY GRAMMARRULES.L %{ #include "y.tab.h" #include <stdio.h> #define YY_DECL extern "C" int yylex() using namespace std; #include <iostream> void ERROR(); %} digit [0-9]+ char [a-zA-Z] op [+\-*/%] %% {digit} {return (DIGIT);} {char} {return (CHARACTER);} {op} {return (OP);} "(" {return (LEFT_PAR);} ")" {return (RIGHT_PAR);} "=" {return (EQUAL);} ";" {return (SEMICOLON);} "\n" {return (NEWLINE);} . {return (OTHER);} %% void ERROR(){ cout << OTHER <<endl; } I have grammar rules and am getting the error undefined reference to 'yylex' in 'yyparse()'
If you're having this issue, both yacc and lex files must be the same name. For example snazzle.l and snazzle.y.
gSOAP: No socket in soap_ssl_accept()
I am trying to setup an example gSOAP server with SSL. I created a self signed certificate as this: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes Then joined the certificates to one file: cat cert.pem key.pem >both.pem And then run this code: #include <stdsoap2.h> #include <stdexcept> #include <sstream> #include <iostream> #define PORT 6667 int main(int argc, char **argv) { struct soap engine(SOAP_C_UTFSTRING); engine.bind_flags=SO_REUSEADDR; soap_ssl_noinit(); int rc = soap_ssl_server_context(&engine, SOAP_SSL_DEFAULT, "both.pem", // keyfile nullptr, // password nullptr, // cacert nullptr, // capath nullptr, // dhfile nullptr, // randfile nullptr // serverid ); if (rc) { std::stringstream error; soap_stream_fault(&engine, error); throw std::runtime_error("soap_ssl_server context failed " + error.str()); } rc = soap_bind(&engine, NULL, PORT, 100); if (rc < 0) { throw std::runtime_error("soap_bind failed " + std::to_string(rc)); } int master_socket = rc; std::cout << "master socket: " << master_socket << std::endl; engine.accept_timeout = 50; engine.send_timeout = 50; engine.recv_timeout = 50; rc = soap_ssl_accept(&engine); if (rc) { soap_stream_fault(&engine, std::cout); throw std::runtime_error("soap_ssl_accept failed " + std::to_string(rc)); } std::cout << "soap_ssl_accept " << rc << std::endl; return 0; } But I get this output: master socket: 3 Error 30 fault detected[no subcode] "SSL/TLS error" Detail: No socket in soap_ssl_accept() terminate called after throwing an instance of 'std::runtime_error' what(): soap_ssl_accept failed 30 What am I doing wrong?
I figured it out. One must call soap_accept before calling soap_ssl_accept. The correct code is: rc = soap_accept(&engine); if (rc) { soap_stream_fault(&engine, std::cout); throw std::runtime_error("soap_accept failed " + std::to_string(rc)); } rc = soap_ssl_accept(&engine); if (rc) { soap_stream_fault(&engine, std::cout); throw std::runtime_error("soap_ssl_accept failed " + std::to_string(rc)); } and then the error is fixed.
error LNK2019: unresolved external symbol (small library)
I've created a small CLR library (MyClient) in VS2005 to integrate threading into an existing C++ application (also written in VS2005). When I build the project get these errors: 1>PSR_CRSDlg.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MyClient::StartClientThread(void)" (?StartClientThread#MyClient##SAXXZ) referenced in function "public: void __thiscall CPSR_CRSDlg::OnBnClickedInit2(void)" (?OnBnClickedInit2#CPSR_CRSDlg##QAEXXZ) 1>PSR_CRSDlg.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MyClient::SendJointValues(double *)" (?SendJointValues#MyClient##SAXPAN#Z) referenced in function "public: void __thiscall CPSR_CRSDlg::OnTimer(unsigned int)" (?OnTimer#CPSR_CRSDlg##QAEXI#Z) 1>PSR_CRSDlg.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MyClient::StopConnection(void)" (?StopConnection#MyClient##SAXXZ) referenced in function "public: void __thiscall CPSR_CRSDlg::OnBnClickedMovepenall(void)" (?OnBnClickedMovepenall#CPSR_CRSDlg##QAEXXZ) 1>D:\Desktop\PSR\Software\Source - June 21\PSR_CRS_SVN - Copy (2)\Debug\PSR_CRS.exe : fatal error LNK1120: 3 unresolved externals I'm new a bit new to C++ and OOP but have been doing it continuously for the past few weeks. This is my .h file: using namespace std; class MyClient { public: static char* createMsg(string s); static char* parseJSON(double j1, double j2, double j3, double j4, double j5, double j6); static void StartConnection(); static void StartClientThread(); static void StopConnection(); static void SendJointValues(double *joints); }; My .cpp file just has the functions instantiated as char* MyClient::createMsg(string s), etc, so I don't think that is the problem. I've also gone through most of the links here and searched a lot to make sure my libraries were all there, no circular lib dependency, library order, etc. Out of the 3 projects in my whole solution, 2 use "No Common Language Runtime support" but my client library uses "Common Language Runtime Support", this is the one difference between the libraries. Does anyone have thoughts on why these errors are occurring? Full Client Library: #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include "stdafx.h" #include <winsock2.h> #include <windows.h> #include <ws2tcpip.h> #include <stdlib.h> #include <iostream> #include <typeinfo> #include <sstream> #include "Client.h" using namespace std; using namespace System; using namespace System::Threading; // Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib #pragma comment (lib, "Ws2_32.lib") #pragma comment (lib, "Mswsock.lib") #pragma comment (lib, "AdvApi32.lib") #define DEFAULT_BUFLEN 4096 #define DEFAULT_PORT "9001" char recvbuf[DEFAULT_BUFLEN]; int iResult; int recvbuflen = DEFAULT_BUFLEN; SOCKET ConnectSocket; char* MyClient::createMsg(string s) { char *a = new char[s.size() + 1]; a[s.size()] = 0; memcpy(a, s.c_str(), s.size()); return a; } char* MyClient::parseJSON(double j1, double j2, double j3, double j4, double j5, double j6) { ostringstream oss; oss << j1 << ',' << j2 << ',' << j3 << ',' << j4 << ',' << j5 << ',' << j6; string joints = oss.str(); return createMsg(joints); } void MyClient::StartConnection() { //printf("Connection Starting... \n"); WSADATA wsaData; ConnectSocket = INVALID_SOCKET; struct addrinfo *result = NULL, *ptr = NULL, hints; int argc = 2; // Validate the parameters if (argc != 2) { printf("usage: %s server-name\n", "client"); return; } // Initialize Winsock iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != 0) { printf("WSAStartup failed with error: %d\n", iResult); return; } ZeroMemory( &hints, sizeof(hints) ); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; // Resolve the server address and port //iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result); iResult = getaddrinfo("localhost", DEFAULT_PORT, &hints, &result); if ( iResult != 0 ) { printf("getaddrinfo failed with error: %d\n", iResult); WSACleanup(); return; } // Attempt to connect to an address until one succeeds for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) { // Create a SOCKET for connecting to server ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); if (ConnectSocket == INVALID_SOCKET) { printf("socket failed with error: %ld\n", WSAGetLastError()); WSACleanup(); return; } // Connect to server. iResult = connect( ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen); if (iResult == SOCKET_ERROR) { closesocket(ConnectSocket); ConnectSocket = INVALID_SOCKET; continue; } break; } freeaddrinfo(result); if (ConnectSocket == INVALID_SOCKET) { printf("Unable to connect to server!\n"); WSACleanup(); return; } return; } void MyClient::StopConnection(){ closesocket(ConnectSocket); WSACleanup(); return; } void MyClient::SendJointValues(double *joints){ char *j; iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0); j = parseJSON(joints[0],joints[1],joints[2],joints[3], \ joints[4],joints[5]); int x = send(ConnectSocket, j, strlen(j), 0); //iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0); } void MyClient::StartClientThread() { Thread^ cln; ThreadStart ^ClientThread = gcnew ThreadStart(&MyClient::StartConnection); cln = gcnew Thread(ClientThread); cln->IsBackground = true; cln->Start(); } Edit: These errors did not occur when I created a dummy application when the same settings as the application I am trying to integrate with right now, which is why I'm not sure what has changed or how to resolve the errors.
I think perhaps you're including the header file from the library in your EXE. When you write a library in C++/CLI, it uses the .Net mechanisms for exported classes. You don't need a header file to declare the class, the .Net metadata takes care of that. Just make sure that your EXE has a the library added as a .Net reference, and just go ahead and use the library class.
So I'm not sure what the exact cause of this specific error was, but overall I found out that I was having a lot of trouble due to the original application using the /MTd runtime library and my new library using /MD
How to fix a warning message associated with strlen() used in Yacc?
Please i need your help. Basically, I am facing this warning message upon compiling with gcc, and am not able to deduce the error: Here are the details: The warning message i am receiving is literrally as follows: y.tab.c: In function ‘yyparse’: y.tab.c:1317 warning: incompatible implicit declaration of built-in function ‘strlen’ My Lex File looks like: %{ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "y.tab.h" void yyerror(const char*); char *ptrStr; %} %START nameState %% "Name:" { BEGIN nameState; } <nameState>.+ { ptrStr = (char *)calloc(strlen(yytext)+1, sizeof(char)); strcpy(ptrStr, yytext); yylval.sValue = ptrStr; return sText; } %% int main(int argc, char *argv[]) { if ( argc < 3 ) { printf("Two args are needed: input and output"); } else { yyin = fopen(argv[1], "r"); yyout = fopen(argv[2], "w"); yyparse(); fclose(yyin); fclose(yyout); } return 0; } My Yacc file is as follows: %{ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "y.tab.h" void yyerror(const char*); int yywrap(); extern FILE *yyout; %} %union { int iValue; char* sValue; }; %token <sValue> sText %token nameToken %% StartName: /* for empty */ | sName ; sName: sText { fprintf(yyout, "The Name is: %s", $1); fprintf(yyout, "The Length of the Name is: %d", strlen($1)); } ; %% void yyerror(const char *str) { fprintf(stderr,"error: %s\n",str); } int yywrap() { return 1; } *I was wondering how to remove this warning message. Please any suggestions are highly appreciated! Thanks in advance.
Include string.h thats where strlen & friends are declared.