1. Download MinGW32 to your local machine so that you can use the gcc compiler and some library files related to linux.
2. the libmemcachedtest program depends on memcached.exe. To compile memcached in win32, You need to modify the code related to the part and socket, and consider that it is only required for test cases, therefore, we decided to modify the configure (the shell file used by autoconfig to generate the makefile configuration information check) file so that libmemcached compilation does not depend on memcached.
3. To complete step 2, you need to manually modify the configure file and comment out the following shell code so that memcached.exe will no longer be used as a required configuration check condition when you execute./configure. Note: Search for -- with-memcached in the file to find the following code:
# Check whether -- with-memcached was given.
# If test "$ {with_memcached + set}" = set; then:
# Withval = $ with_memcached; ac_cv_with_memcached = "$ withval"
# Else
# Ac_cv_with_memcached = memcached
# Fi
# Just ignore the user if -- without-memcached is passed... it is
# Only used by make test
# If test "x $ withval" = "xno"; then:
#
# Ac_cv_with_memcached = memcached
# MEMC_BINARY = memcached
# Else
#
# If test-f "$ withval"; then:
#
# Ac_cv_with_memcached = $ withval
# MEMC_BINARY = $ withval
#
# Else
#
# Extract the first word of "$ ac_cv_with_memcached", so it can be a program name with args.
# Set dummy $ ac_cv_with_memcached; ac_word = $2
# {$ As_echo "$ as_me :$ {as_lineno-$ LINENO}: checking for $ ac_word"> & 5
# $ As_echo_n "checking for $ ac_word..."> & 6 ;}
# If test "$ {ac_cv_path_MEMC_BINARY + set}" = set; then:
# $ As_echo_n "(cached)"> & 6
# Else
# Case $ MEMC_BINARY in
# [\/] * |? : [\/] *)
# Ac_cv_path_MEMC_BINARY = "$ MEMC_BINARY" # Let the user override the test with a path.
#;;
#*)
# As_save_IFS = $ IFS; IFS = $ PATH_SEPARATOR
# For as_dir in $ PATH
# Do
# IFS = $ as_save_IFS
# Test-z "$ as_dir" & as_dir =.
# For ac_exec_ext in ''$ ac_executable_extensions; do
# If {test-f "$ as_dir/$ ac_word $ ac_exec_ext" & $ as_test_x "$ as_dir/$ ac_word $ ac_exec_ext" ;}; then
# Ac_cv_path_MEMC_BINARY = "$ as_dir/$ ac_word $ ac_exec_ext"
# $ As_echo "$ as_me :$ {as_lineno-$ LINENO}: found $ as_dir/$ ac_word $ ac_exec_ext"> & 5
# Break 2
# Fi
# Done
# Done
# IFS = $ as_save_IFS
# Test-z "$ ac_cv_path_MEMC_BINARY" & ac_cv_path_MEMC_BINARY = "" no ""
#;;
# Esac
# Fi
# MEMC_BINARY = $ ac_cv_path_MEMC_BINARY
# If test-n "$ MEMC_BINARY"; then
# {$ As_echo "$ as_me :$ {as_lineno-$ LINENO}: result: $ MEMC_BINARY"> & 5
# $ As_echo "$ MEMC_BINARY"> & 6 ;}
# Else
# {$ As_echo "$ as_me :$ {as_lineno-$ LINENO}: result: no"> & 5
# $ As_echo "no"> & 6 ;}
# Fi
#
#
# If test "x $ MEMC_BINARY" = "xno"; then:
# As_fn_error $? "\" Cocould not find memcached binary \ "" $ LINENO "5
# Fi
#
# Fi
#
# Fi
# Cat> confdefs. h <_ ACEOF
# Define MEMCACHED_BINARY "$ MEMC_BINARY"
# _ ACEOF
4. from the code above, we can find that the MEMCACHED_BINARY macro needs to be used in the program. In this case, you need to manually modify the place where the macro is used, as follows: (See libtest/server. c. Search for the string MEMCACHED_BINARY at the same time)
If (x = 0)
{
// Original code
// Snprintf (buffer, sizeof (buffer), "% s-d-P % s-t 1-p % u-U % u-m 128 ",
// MEMCACHED_BINARY, construct-> pid_file [x], construct-> port [x], construct-> port [x]);
// Change
Snprintf (buffer, sizeof (buffer), "-d-P % s-t 1-p % u-U % u-m 128 ",
Construct-> pid_file [x], construct-> port [x], construct-> port [x]);
}
Else
{
// Original code
// Snprintf (buffer, sizeof (buffer), "% s-d-P % s-t 1-p % u % U ",
// MEMCACHED_BINARY, construct-> pid_file [x], construct-> port [x], construct-> port [x]);
// Change
Snprintf (buffer, sizeof (buffer), "-d-P % s-t 1-p % u-U % u ",
Construct-> pid_file [x], construct-> port [x], construct-> port [x]);
}
5. comment out the/# include <arpa/inet. h> code in./libmemcached/options/server. h because the file is not in win32.
6. since it was initially decided not to compile the test case. /libtest/server. part of the code in the c file is commented out. Here, I will comment out some of the code related to linux using the following method: (Note: you cannot comment out all the files, because other test files need to rely on the functions declared here, if all comments are made, other test files will not be properly linked)
# Ifndef WIN32
Static struct timespec global_sleep_value = {. TV _sec = 0,. TV _nsec = 50000 };
# Endif
Static void kill_file (const char * file_buffer)
{
# Ifndef WIN32
......
# Endif
}
Void server_startup (server_startup_st * construct)
{
# Ifndef WIN32
......
# Endif
}
7. modify. the three files in the/libmemcached/options/directory are parser. cc, parser. h, large. cc. The three files contain four enumeration members, including ERROR, TRUE, FALSE, and FLOAT. The compilation fails due to the corresponding macro conflict with win32, in particular, errors related to yacc and lex will also be reported. In these three files, I will change all the areas related to the four enumeration to ERROR1 and TRUE1, FALSE1 and FLOAT1. (Case Sensitive)
// 1. The code is located in parser. h.
Enum yytokentype {
COMMENT = 258,
End= 259,
ERROR1 = 260,
......
TRUE1 = 315,
FALSE1 = 316,
FLOAT1 = 317,
......
}
// 2. The code is located in parser. cc.
Enum yytokentype {
COMMENT = 258,
End= 259,
ERROR1 = 260,
......
TRUE1 = 315,
FALSE1 = 316,
FLOAT1 = 317,
......
}
Static const char * const yytname [] =
{
"$ End", "error", "$ undefined", "COMMENT", "END", "ERROR1 ",
......
"TRUE1", "FALSE1", "','", "'='", "FLOAT1", ......, 0
};
// 3. The code is located in response. cc.
Case 44:
YY_RULE_SETUP
# Line 133 "libmemcached/options/limits. l"
{Yyextra-> begin = yytext; return ERROR1 ;}
YY_BREAK
Case 45:
YY_RULE_SETUP
# Line 135 "libmemcached/options/limits. l"
{Return TRUE1 ;}
YY_BREAK
Case 46:
YY_RULE_SETUP
# Line 136 "libmemcached/options/limits. l"
{Return FALSE1 ;}
YY_BREAK
8. comment out. /clients/memslap. the following code in c // # include <sys/mman. h> because the file is a linux memory-managed file, win32 does not provide the corresponding file, so you can comment it out directly.
9. Finally, modify the three functions related to access in./tests/parser. cc (access is a file-related function in linux), where # ifndef WIN32 is newly added.
Test_return_t memcached_create_with_options_with_filename (memcached_st *)
{
# Ifndef WIN32
If (access (SUPPORT_EXAMPLE_CNF, R_ OK ))
Return TEST_SKIPPED;
Memcached_st * memc_ptr;
Memc_ptr = memcached (STRING_WITH_LEN ("-- CONFIGURE-FILE = \" support/example. cnf \""));
Test_true_got (memc_ptr, memcached_last_error_message (memc_ptr ));
Memcached_free (memc_ptr );
# Endif
Return TEST_SUCCESS;
}
Test_return_t libmemcached_check_configuration_with_filename_test (memcached_st *)
{
# Ifndef WIN32
If (access (SUPPORT_EXAMPLE_CNF, R_ OK ))
Return TEST_SKIPPED;
Memcached_return_t rc;
Char buffer [BUFSIZ];
Rc = libmemcached_check_configuration (STRING_WITH_LEN ("-- CONFIGURE-FILE = \" support/example. cnf \ ""), buffer, sizeof (buffer ));
Test_true_got (rc = MEMCACHED_SUCCESS, buffer );
Rc = libmemcached_check_configuration (STRING_WITH_LEN ("-- CONFIGURE-FILE = support/example. cnf"), buffer, sizeof (buffer ));
Test_false_with (rc = MEMCACHED_SUCCESS, buffer );
Rc = libmemcached_check_configuration (STRING_WITH_LEN ("-- CONFIGURE-FILE = \" bad-path/example. cnf \ ""), buffer, sizeof (buffer ));
Test_true_got (rc = MEMCACHED_ERRNO, buffer );
# Endif
Return TEST_SUCCESS;
}
Test_return_t test_include_keyword (memcached_st *)
{
# Ifndef WIN32
If (access (SUPPORT_EXAMPLE_CNF, R_ OK ))
Return TEST_SKIPPED;
Char buffer [BUFSIZ];
Memcached_return_t rc;
Rc = libmemcached_check_configuration (STRING_WITH_LEN ("INCLUDE \" support/example. cnf \ ""), buffer, sizeof (buffer ));
Test_true_got (rc = MEMCACHED_SUCCESS, buffer );
# Endif
Return TEST_SUCCESS;
}
10. Remember to make install after successful compilation.
From steen_liu