I get the above message linker error for a global
const char* HOST_NAME = "127.0.0.1";
I don't think that I have compiled some files twice but here's my definition of the files anyway.
main.cpp
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include "connection.hpp"
connection.cpp
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "connection.hpp"
connection.hpp
#ifndef __connection__
#define __connection__
#include <unistd.h>
#include <netinet/in.h>
const int BUFFSIZE = sysconf(_SC_PAGESIZE); //Define page size
const char* HOST_NAME = "127.0.0.1"; //Local host
//Definition of a class
#endif
Any help?
HOST_NAME
is also defined in one of the headers you include. Put the definition ofHOST_NAME
in a namespace. – BowensHOST_NAME
const so it will get internal linkage? – MinutesHOST_NAME
is not const. It points to const data. You're looking forconst char * const HOST_NAME
. – Rahm