# Mysql from C: Can't initialize character set



## mack3457 (Feb 5, 2013)

Hi!
When compiling a test program statically, I end up with an error message from MySQL when trying to connect to the MySQL server, but there is no problem when linking dynamically.

The test program:

```
int main(int argc, char *argv[]) {
	MYSQL *mysql;

	if (mysql_library_init(0, NULL, NULL)) {
		fprintf(stderr, "Error 1: %s\n", mysql_error(mysql));
		exit(-1);
	}
	mysql = mysql_init(NULL);
	if (!mysql_real_connect(mysql, "db.some.host","dbuser","something_secret", "db", 0,NULL,0)) {
		fprintf(stderr, "Error 2: %s\n", mysql_error(mysql));
		exit(-1);
	}
}
```


The output on static compile with: [CMD=""]gcc -static -o mt -I/usr/local/include/mysql -L/usr/local/lib/mysql mt.c -lmysqlclient[/CMD]



```
[mack@admin ~/sources]$ ./mt
Character set 'latin1' is not a compiled character set and is not specified in the '/usr/local/share/mysql/charsets/Index.xml' file
Error 2: Can't initialize character set latin1 (path: /usr/local/share/mysql/charsets/)
[mack@admin ~/sources]$ grep -w latin1 /usr/local/share/mysql/charsets/Index.xml
<charset name="latin1">
  <alias>latin1</alias>
[mack@admin ~/sources]$
```

There is no problem, when leaving *-static* from the compile.

So, what might be the problem?


```
[mack@admin ~/sources]$ pkg_which /usr/local/lib/mysql/libmysql*.a
mysql-client-5.5.29
mysql-client-5.5.29
mysql-server-5.5.29
mysql-client-5.5.29
[mack@admin ~/sources]$
```

Any hint?

Thanks,
Thomas


----------



## expl (Feb 5, 2013)

Try to link against libmysqlclient_r.a instead of libmysqlclient.a. If I remember good, the non-threaded mysql libraries do not work on FreeBSD.


----------



## mack3457 (Feb 6, 2013)

Oh yes. Unfortunately, libmysqlclient_r.a is just a link to libmysqlclient.a, so it didn't resolve the problem.

It looks like a bug to me, so I started a bug report on it (PR 175872).


----------



## expl (Feb 6, 2013)

mack3457 said:
			
		

> Oh yes. Unfortunately, libmysqlclient_r.a is just a link to libmysqlclient.a, so it didn't resolve the problem.
> 
> It looks like a bug to me, so I started a bug report on it (PR 175872).



You are probably right about it being a port bug, I suspect that the static library is built with compile time configuration for non-threaded mode and would explain your error.


----------



## mack3457 (Feb 8, 2013)

No, it's not a bug - the -pthread option was missing, as was noted on the bug report.

I recompiled after a 7.1 upgrade to 8.3, and didn't see the necessity to change compiler options. I seem to have missed something.


----------

