g++ linking library

Hello, I am trying to compile a program to use mysql-connector-c++. I'm working on Mac and installed via homebrew(package utility). It linked it to /usr/local/lib but I still can not manage to get my library connected. My make file keeps giving an error of lib not found when I run.

Makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
CC = g++

CFLAGS= -c -Wall

LINKFLAGS= -llibmysql.dylib


all: main.out

main.out: main.cpp classes/database.cpp classes/configuration.cpp
	$(CC) $(LINKFLAGS) -o main.out main.cpp classes/database.cpp classes/configuration.cpp


#END OF MAKE FILE 


And my main_header.h file:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdlib.h>
#include <iostream>
#include <string>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h> 


And here is the error that I got when trying to build

1
2
3
ld: library not found for -llibmysql.dylib
collect2: ld returned 1 exit status
make: *** [main.out] Error 1
The -l flag strips the 'lib' prefix and the '.(so|a)' suffix
By instance -lGL means to link against /usr/lib/libGL.so

If your library doesn't follow the name convention then just add it as another object file
g++ graph.o /usr/lib/libGL.so



Also, you may want to compile your sources.
thanks, worked like a charm with the mysqlcppconn lib. This was the first make file I've ever done so thanks for the help on such a basic problem.
closed account (S6k9GNh0)
For reference, -lGL doesn't actually mean to link against "/usr/lib/libGL.so", it means to search through every directory the linker is provided (which by default is "/usr/lib/", "/usr/local/lib/", and a few others that are distro specific). Then link to the *first* instance of that library found.
Last edited on
Topic archived. No new replies allowed.