'How Do I Specify Additional Dependencies running Visual Studio from Command Line?

On Windows 10 I am trying to compile the following program from the book MySql by Paul DuBois using Visual Studio 2022:

#include <stdio.h>
#include <mysql.h>

#define def_host_name   "localhost"    /* host to connect to     */
#define def_user_name   "xxx"          /* user name              */
#define def_password    "yyyyyy"       /* user password          */
#define def_db_name     NULL           /* database to connect to */

MYSQL *conn;    /* pointer to connect handler */

int main (int argc, char *argv[])
{
        conn = mysql_init(NULL);

        mysql_real_connect( conn,           /* pointer to connection handler */
                            def_host_name,  /* host to connect to            */
                            def_user_name,  /* user name                     */
                            def_password,   /* user password                 */
                            def_db_name,    /* database to connect to        */
                            0,              /* port (using default)          */
                            NULL,           /* socket (use default)          */
                            0               /* flags (none)                  */
                           );
        mysql_close(conn);
        exit(0);
}

It compiles and runs using the Visual Studio 2022 IDE with the following setting:

Additional Include Directories: C:\Program Files\MySQL\MySQL Server 8.0\include Linker Additional Aibrary Directories: C:\Program Files\MySQL\MySQL Server 8.0\lib Linker Input Additional Dependences: mysqlclient.lib

I am unable to compile from the command line. For example:

CL client1.c /I "C:\Program Files\MySQL\MySQL Server 8.0\include" /link "C:\Program Files\MySQL\MySQL Server 8.0\lib\mysqlclient.lib"

client1.obj
client1.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function _main
client1.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function _main
client1.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function _main
C:\Program Files\MySQL\MySQL Server 8.0\lib\mysqlclient.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
client1.exe : fatal error LNK1120: 3 unresolved externals

What command line should I be using?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source